• Post Reply Bookmark Topic Watch Topic
  • New Topic

Integer wrapper class behaviour  RSS feed

 
balamurugan rajkumar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 5652
765
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This Topic would be helpful.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this out
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!