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.