false true integer prec limit,it will give true true till 127 no after that.
Yeah , what's mentioned is perfectly correct. Till the point Integer value <= 127 , both the Integer objects will have the same value as well as the same reference. Only one object is created for both the statements.
However, here you haev Integer = 200. Which is more then 127 . In that case , there are separate objects created for both. Therefore, System.out.print(i==j); will be False ( They are not the same objects)
and System.out.print(i.equals(j)); will be True - they have the same value ie.200
Hope that helps.
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Hi.. The answer is false true According to the explanation given in K&B, "In order to save memory, two instances of the following wrapper objects will always be == when their primitive values are the same: Boolean Byte Character from \u0000 to \u007f (7f is 127 in decimal) Short and Integer from -128 to 127 "
Since the values of i and j exceed 127 (i.e 200) they are created as 2 separate wrapper objects, with different references. That is why, the == comparison returns false, whereas the equals comparison which looks for the primitive value/content returns true. [ July 08, 2008: Message edited by: Meena Subramanian ]