What's the difference between the == operator and the equals() method? What test does Object.equals() use, and why?

The == operator would be used, in an object sense, to see if the two objects were actually the same object. This operator looks at the actually memory address to see if it actually the same object. The equals() method is used to compare the values of the object respectively. This is used in a higher level to see if the object values are equal. Of course the the equals() method would be overloaded in a meaningful way for whatever object that you were working with.

Showing Answers 1 - 3 of 3 Answers

suresh

  • Jan 25th, 2006
 

the diffrence between equals and == is equals method compares char inside the string where as == compares object instances

object.equals() is used to compare two objects why because == compares references of the object and equals compares objects as it is

  Was this answer useful?  Yes

vijay saxena

  • Oct 23rd, 2006
 

Object.equals()  will certainly calls for member function becs it is invoked by its object. although the worked is same in function code as well as == opearor overloading, but variation is in methods.

by writing o1==o2 then it will calls for overloding and one object argument will must be passed.

  Was this answer useful?  Yes

MANISHA PATHAK

  • Oct 26th, 2006
 

== operator is used to compare whether the two references where equal or not.

ex. String s1="abc";

     String s2="xyz";

     In this case if we compare if(s1==s2) , it will return false.

     s1=s2;

    Now, in this case if we compare if(s1==s2) , it will return true

equals() is used to find whether two objects where meaningfully equal or not.

 ex.  String s1="abc";

       String s2="abc";

In this case, s1.equals(s2) returns true.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.