The key difference between equals and hashCode in Java is that the equals is used to compare two objects while the hashCode is used in hashing to decide which group an object should be categorized into .
Read moreWhat is the relation between equals and hashCode in Java?
hashCode() and equals() contract The basic rule of the contract states that if two objects are equal to each other based on equals() method, then the hash code must be the same , but if the hash code is the same, then equals() can return false.
Read moreHow hashCode () and equals () method are used in HashMap?
In HashMap, hashCode() is used to calculate the bucket and therefore calculate the index. equals method is used to check that 2 objects are equal or not . This method is provided by Object class. You can override this in your class to provide your own implementation.
Read more