Java String hashCode() Method with Examples
The Java String hashCode() method is used to return the particular value’s hash value. The hashCode() uses an internal hash function that returns the hash value of the stored value in the String variable.
Hash Value: This is the encrypted value that is generated with the help of some hash function. For example, the hash value of ‘A’ is 67.
The hashCode() method of Java String is the method of the object class that is the parent class of all the classes in java. The string class also inherits the object class. That’s why it is available in the String class. The hashCode is used for the comparison of String objects. A code hash function always returns the unique hash value for every String value.
The hashCode() method is the inherited method from the Object class in the String class that is used for returning the hash value of a particular value of the String type.
Parameter: This method doesn’t take any parameters.
Return type: This method returns the hash value in int format.
Comparing two String values using hashCode().