| Author |
Integer wrapper class behaviour
|
balamurugan rajkumar
Greenhorn
Joined: Jun 27, 2009
Posts: 2
|
|
consider the following two cases
1)
Integer i3 = 127;
Integer i4 = 127;
if(i3 == i4) System.out.println("same object");
-----------
2)
Integer i3 = 128;
Integer i4 = 128;
if(i3 == i4) System.out.println("same object");
-------------
in case 1 we get same object as output. In the second case we don't get same object printed.
when the object i3 & i4 is compared using '==' with values between -128 to +127, the system prints same object. for any other value the same object is not printed.
could anyone explain why this happens and the reason?? thanks a lot in advance...
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2693
|
|
|
This Topic would be helpful.
|
Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
|
 |
Muhammad Khojaye
Ranch Hand
Joined: Apr 12, 2009
Posts: 341
|
|
|
Check this out
|
http://muhammadkhojaye.blogspot.com/
|
 |
 |
|
|
subject: Integer wrapper class behaviour
|
|
|