This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes double equal sign vs equals() method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "double equal sign vs equals() method" Watch "double equal sign vs equals() method" New topic
Author

double equal sign vs equals() method

Nick Petas
Ranch Hand

Joined: Jan 31, 2007
Posts: 38
When I compare two objects which of the two ways I must choose?
Thank you very much!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
== tells you whether they are both the same object.
equals() tells you that they satisfy whatever criteria that class has to be regarded as equal.
If the API documentation for your class has "equals" under "methods inherited from Object" then it simply uses == to see whether both Objects are the same object.
Look at a few other threads which might help: 1 2 3 4. And there will be many others.
 
jQuery in Action, 2nd edition
 
subject: double equal sign vs equals() method
 
Similar Threads
I see results posted!
503 error
what is wrong with this?
JP Morgan chase - Interview - UK
How long the Certification (SCWCD) is Valid?