This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "double equal sign vs equals() method" Watch "double equal sign vs equals() method" New topic

double equal sign vs equals() method

Nick Petas
Ranch Hand

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

Joined: Oct 13, 2005
Posts: 43958
== 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.
I agree. Here's the link:
subject: double equal sign vs equals() method
It's not a secret anymore!