• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

== and equals  RSS feed

 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code snippet :

Integer i1 = 1000;
Integer i2 = 1000;

if(i1 != i2)
System.out.println("different objects");
if(i1.equals(i2))
System.out.println("meaningfully equal");

Produces output :

different objects
meaningfully equal

However,

Integer i1 = 10;
Integer i2 = 10;

if(i1 == i2)
System.out.println("same objects");
if(i1.equals(i2))
System.out.println("meaningfully equal");

Produces output :

same objects
meaningfully equal

Could someone explain the output in both scenarios ?
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question has been asked many times so a quick search will definitely help.
 
Marshal
Posts: 60766
189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree. This is one of the things which comes up on such a search.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!