Possible Duplicate:
Weird Java Boxing
Hi,
Can somebody explain why the last print returns false ?
int a = 100;
int b = 100;
System.out.println(a == b); // prints true
Integer aa = 100;
Integer bb = 100;
System.out.println(aa == bb); // prints true
Integer aaa = 1000;
Integer bbb = 1000;
System.out.println(aaa == bbb); // prints false
Thanks
Michael
The reason why the second print evaluates to true is because the first 128 Integer objects are cached by the Integer class. You want to use .
equals