hii geeteha i1 ,12 ,i3,i4,i5,i6 are all different instances of the Integer wrapper class and saurabh has mentioned the == ooperator returns true only when both the objects are indeed one ,which in our case is not true hence the output will be
Originally posted by Geetha Arthanari: Hi Saurabh, I'm asking why i1 and i2 are equal. i3 and i4 are equal but i5 and i6 are not equal.
The boxing of integers uses an integer cache. Basically, -128 to 127 are cached when they are boxed, hence, you always get the same one during boxing of numbers in this range.
Interestingly, the specification states that this range must be cache, but it makes no mention of what happens outside this range. This means that in the future, with a new JVM, i5 and i6 may be equal.