I know this: When you use == to compare two objects it will compare the two instances of the object and check if they are the equal. When you use .equals() it will compare the states of the 2 objects.
Let's say this is my code:
String string1 = new String("abc");
String string2 = new String("abc");
Integer integer1 = new Integer(5);
Integer integer2 = new Integer(5);
int int1 = new Integer(6);
int int2 = new Integer(6);
if (string1 == string2)
System.out.println("The strings are equal");
if (integer1 == integer2)
System.out.println("The integers are equal");
if (int1 == int2)
System.out.println("The ints are equal");
Why will this code only print "The ints are equal"?