The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Re: Comparing Objects

Posted by Brian Sanders on November 29, 2001 at 4:32 PM

String values are Objects. You compare Objects using the .equals() method. So, your code above would be:

if (Global.name1.equals(Global.name2))

When you use the == operator on Objects, what you're really doing is comparing the Object references. So, this is equivalent to asking, "Does the object reference on the left side of the == point to the same address in memory as the object reference on the right side of the ==?"


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us