This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object refer same memory location

 
jacob deiter
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Read some article ,it says that if two Objects (EX: String ) has the same value then it refer to same memory location.

But It Try that with == operator but it return false.

Please explain this?
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jacob deiter wrote:In Read some article ,it says that if two Objects (EX: String ) has the same value then it refer to same memory location.

I'd like to see a link to that article, because as a general statement, it is false. It is true however, that if Strings have the same value, they can often refer to the same object which is located in the String pool, but there's no guarantee for this. It is best to compare Strings for equality using the equals or equalIgnoreCase methods.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jacob deiter wrote:In Read some article ,it says that if two Objects (EX: String ) has the same value then it refer to same memory location.


See the Strings, Literally article may help you.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muhammad Ali Khojaye wrote:See the Strings, Literally article may help you.
That looks a nice article.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic