This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

== 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: 62275
193
  • 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.
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!