This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Integer wrapper class behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Integer wrapper class behaviour" Watch "Integer wrapper class behaviour" New topic
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
    
    3

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/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integer wrapper class behaviour
 
Similar Threads
SCJP 1.5 "In order to save memory ??" QUOTE
Integer's == and !=
Integer wrapper class behaviour
OO basics doubt
boxing,==, and equals()