Equals () is A method provided by the object class, and it is well known that each Java class inherits from Object, So every object has a equals () method, which we generally override when we use this method.
The equals () method in the Object class source code
Public Boolean equals (Object obj) { return ( this = = obj); }
At this point the comparison is whether two references point to the same object, which is often used when we want to compare the logical equality of two objects
the String class overrides the equals () method, so:
String a=New string ("AA"); String b= "AA"; System.out.println (A.equals (b)); // true System.out.println (a==b); // false System.out.println (A.hashcode ()); System.out.println (B.hashcode ());
The Hashcode () method is also inherited from the object class, which returns the hash code value of an object, which is usually the integer returned by the internal address of the objects, and is implemented primarily to improve the performance of the hash table.
The return value of Hashcode () is related to equals () as follows
If x.equals (y) returns true , then the x and y hashcode () values must be equal
If x.equals (y) returns false , then the x and Y Hashcode () values may be equal and may vary
Overriding the equals () method will override the hashcode () method
[Android] Watch blog Learning hashcode () and Equals ()