The Hashcode method Returns the hash code value of the object. This method is supported to provide some advantages to the hash table, for example, the Hashtable provided by Java.util.Hashtable.
The general agreement of Hashcode is:
During Java application execution, when the Hashcode method is called multiple times on the same object, the same integer must be returned consistently, provided that the information used in the Equals comparison on the object has not been modified. The integer does not need to be consistent from one execution of an application to another execution of the same application.
If two objects are equal according to the Equals (object) method, calling the Hashcode method on each object in two objects must produce the same integer result.
The following conditions are not required: If two objects are not equal according to the Equals (Java.lang.Object) method, then calling the Hashcode method on any of the two objects must produce a different integer result. However, programmers should know that generating different integer results for unequal objects can improve the performance of the hash table.
In fact, the Hashcode method defined by the object class does return different integers for different objects. (This is typically done by converting the object's internal address to an integer, but the JAVATM programming language does not require this implementation technique.) When the Equals method is overridden, it is often necessary to override the Hashcode method to maintain the general contract of the Hashcode method, which declares that the equality object must have an equal hash code.
The equals method , which is inherited by the string class from its superclass object, is used to detect whether two objects are equal, that is, whether the contents of two objects are equal and case-sensitive.
Used to compare references and compare basic data types with different features:
Compare basic data types, if two values are the same, the result is true
When comparing references, the result is true if the reference points to the same object in memory
The hashcode is used for lookups, while equals is used to compare the equality of two objects.
Java EE 8