Computer Science, asked by T4Talent, 1 year ago

(a) State the difference between == operator and equals() method.

Answers

Answered by tiara5
3

Ans. == compares if the two objects being compared refer to the instance while equals() method which can be overridden by classes generally compares if the contents of the objects are equals.



Answered by oswin
10
== operator - it is the equality operator
                    - checks if both the object references refer to the same memory                            location.e.g. if(a==b)it means it verifies whether both a and b refers to the same location in memory.  

equals()-it is for content comparison
             -compare the value.e.g String a="home";String b="home";String c="sweet";
if(a.equals(b))returns true because both contain the same value.
if(a.equals(c))returns false because a and c contents are different.

Similar questions