Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

equals operator and a graph node

Thread view: 
Monty Hall - 06 Nov 2005 07:43 GMT
Hello,

Suppose I have an object that's a vertex in a graph.  Supppose I have a
vector that contains this vertex.  Suppose I use the vector's
contain(Object) method.  Does java first compare by memory reference ?  Or
does it do a "deep" equals?

Monty.
Thomas Hawtin - 06 Nov 2005 08:46 GMT
> Suppose I have an object that's a vertex in a graph.  Supppose I have a
> vector that contains this vertex.  Suppose I use the vector's
> contain(Object) method.  Does java first compare by memory reference ?  Or
> does it do a "deep" equals?

What does the documentation say?

http://download.java.net/jdk6/docs/api/java/util/Collection.html#contains(java.l
ang.Object
)

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Chris Uppal - 06 Nov 2005 09:37 GMT
> Suppose I use the vector's
> contain(Object) method.  Does java first compare by memory reference ?  Or
> does it do a "deep" equals?

It uses the object's equals() method which by default is the same as comparing
by ==, but may be overridden to do a more meaningful comparison.  So the answer
is that it depends on the objects in question.

Incidentally, this is specified in the JavaDoc for java.util.Vector.contains(),
though I admit it doesn't exactly jump out at you when you read it.

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.