• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object refer same memory location

 
jacob deiter
Ranch Hand
Posts: 583
  • 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
  • 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
  • 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
Posts: 48382
56
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic