It's not a secret anymore!
The moose likes Beginning Java and the fly likes 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 "equals() method" Watch "equals() method" New topic

equals() method

Ramm Kummar

Joined: Feb 10, 2009
Posts: 26
Does this statement is right?

The equals() method in class Object uses only the == operator for comparisons,
so unless you override equals(), two objects are considered equal only if the two
references refer to the same object.

So both equals and == returns the same if equals is not overidden.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

This statement is an extract of the API. Check java.lang.Object.

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

[My Blog]
All roads lead to JavaRanch
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
nice picture of you here
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10828

Sachin Ramesh Tendulkar wrote:

Please check your private messages for an important administrative matter.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
I agree. Here's the link:
subject: equals() method
It's not a secret anymore!