This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Object refer same memory location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object refer same memory location" Watch "Object refer same memory location" New topic
Author

Object refer same memory location

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Apr 12, 2009
Posts: 449

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.


http://muhammadkhojaye.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37941
    
  22
Muhammad Ali Khojaye wrote:See the Strings, Literally article may help you.
That looks a nice article.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Object refer same memory location
 
Similar Threads
What is the use of Clone and Equal?
How to print reference of String Object ?
String
Strings doubt
difference between == and equal() in sting