HashSet hashCode() method in Java with Example
The hashCode() method of HashSet in Java is used to get the hashCode value for this instance of the HashSet. It returns an integer value which is the hashCode value for this instance of the HashSet.
public int hashCode()
Parameters: This function has no parameters.
Returns: The method returns an integer value which is the hashCode value for this instance of the HashSet.
Below examples illustrates the HashSet.hashCode() method:
HashSet: [1, 2, 3, 4] HashCode value: 10
HashSet: [ForGeeks, Geeks, For, GeeksForGeeks] HashCode value: -482506029
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.