String test1 = "test";
String test2 = "test";
System.out.println(test1 == test2); // true
test1 and test2 points to the same object, so the outcome is true.
String test1 = new String("test");
String test2 = new String("test");
System.out.println(test1 == test2); // false
test1 and test2 points to the different object, so the outcome is false.
so the question is that, what is the difference between,
int[] test = {1,2,3}; // literal
int[] test = new int[] {1,2,3}; // non-literal
I am confused of this since,
int[] test1 = new int[]{1,2,3};
int[] test2 = new int[]{1,2,3};
System.out.println(test1 == test2); // false
and
int[] test1 = {1,2,3};
int[] test2 = {1,2,3};
System.out.println(test1 == test2); // also prints false
I expected that the latter case`s outcome would be true, the same reason with the case of String example above.
Is test1 and test2 pointing at the different array object?