hashCode()
function in the Object class. This function returns an integer that can be used to create good hash tables.129382981
and we have 10
buckets, then we put it in bucket 1
, or 129382981 % 10
.N/M
, where N is the number of items and M is the number of buckets. For example, a load ratio of 2 will mean the table resizes when, on average, each bucket has 2 items in it.HashSet
and HashMap
which are the most popular implementation of sets and maps.hashCode()
method. Be careful when doing this because hashCode()
relies on equals()
to find which bucket objects are in! So, if hashCode is overridden, it is highly recommended to override equals as well to ensure that they are compatible.