The most intelligent Java IDE
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of JBoss AS 5 Development this week in the JBoss forum
or Spring Dynamic Modules in Action in the Spring forum!
Reply locked JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
Author

Integer wrapper class behaviour

balamurugan rajkumar
Greenhorn

Joined: Jun 27, 2009
Messages: 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
Rancher

Joined: Jul 29, 2008
Messages: 1108

Please CarefullyChooseOneForum. I replied in your other topic.

Author of ExamLab - the free mock exam kit for SCJP (Write a Review)
[My Home Page] . [Twitter Profile] . [JavaRanch FAQ] . [How to Ask a Question]
Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14514

Devaka Cooray wrote:Please CarefullyChooseOneForum. I replied in your other topic.
And I closed this one.
 
 
 
Reply locked JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
IntelliJ open source

trailboss links:

permaculture
diatomaceous earth
Sepp Holzer
rocket mass heater
raising chickens
cast iron
lawn care