Difference between string equals and object equals in JAVA?
10089 Views
sno
String.equals()
Object.equals()
1
Compares the value of two strings.
Compares hashCode value of two objects. hashCode is a unique integer to access the memory. Same object represents same hashCode value. Find hashCode value by hashCode() method of Object class.
2
Both are returns boolean. It returns false when both string values are not equals otherwise true.
Returns true if both objects are pointing same memory otherwise false.
3
String obj1 == String obj2. Compares the memory of the objects. If both objects are pointing same memory then it returns ture otherwise false.
Object obj1 == Object obj2 - double equals(==) compares the reference of the objects. so if this both obj1 and obj2 are in same reference memory then it return true or false. same as Object.equals() method.