This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.