File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Integer wrapper class behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
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: 2595

This Topic would be helpful.


Author of ExamLab - 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: 340
Check this out


http://muhammadkhojaye.blogspot.com/
 
 
subject: Integer wrapper class behaviour
 
Threads others viewed
Integer's == and !=
OO basics doubt
SCJP 1.5 "In order to save memory ??" QUOTE
boxing,==, and equals()
Integer wrapper class behaviour
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com