Integer i1 = 10;
Integer i2 = 10;
Integer i3 = new Integer(10);
Integer i4 = new Integer(10);
System.out.println("i1 == i2: " + (i1== i2) + " i3 == i4: " + (i3== i4));
Till 127
Java will cache the values and hence i1 and i2 will refere to same single Integer(10) object in heap. But when you do i3 = new Integer(10) you are telling the compiler to create a new integer object.
And hence in the above code i1 == i3 you get false instead of getting true.
Only during autoboxing as with i1 and i2 java will cache the values and make the references to point to same immutable 10 value.
Thanks
Deepak