Originally posted by Sathya Shanmugam:
hi Java folks,
Could anyone give some explanation for the example below
Integer i3 = 1000;
Integer i4 = 1000;
if (i3 == i4) System.out.println("same object");
if (i3.equals(i4)) System.out.println("meaningfully equal");
if (i3 != i4) System.out.println("different objects");
o/p
same object
meaningfully equal
different objects
how come its displaying both same and different objects. pls give me some explanation..
Thanks
-----------------<br />SCJP 1.4<br />Target SCWCD by December 2007
Integer i3 = 1000;
Integer i4 = 1000;
if (i3 == i4) System.out.println("same object");
if (i3.equals(i4)) System.out.println("meaningfully equal");
if (i3 != i4) System.out.println("different objects");
o/p
same object
meaningfully equal
different objects
Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
Regards, Sanjay Singh
SCJP-1.6, OCEWCD 6
"Integer i = 100;"
Here is my concern about this question. How can we assign primitive type int to Integer object, as written in the above code?
cmbhatt
Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
It will give me the powers of the gods. Not bad for a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|