I'm reading SCJP Java 6 by Kathy Sierra and Bert Bates and this book is confusing me so much. On page 245 they state that the following code below.
Integer i1 = 1000;
Integer i2 = 1000;
if(i1 != i2)
Integer i3 = 10;
Integer i4 = 10;
if(i3 == i4)
The key to the answer is called object interning. Java interns small numbers (less than 128), so all instances of
n in the interned range are the same. Numbers greater than or equal to 128 are not interned, hence
Integer(1000) objects are not equal to each other.