I created one hashmap so default size will be 16. I overide the equals and hashcode method. And I am returning 20 from hashcode method. So now we have bucket 0-15 in map but hashcode value is 20 so which bucket will be using for insert this key?
The HashMap does not use the value returned by the hashCode methods directly. It uses them for some kind of modulo operation, using its own hashing method which obeys some nice mathematical properties.
HashMapdoes not use the value returned by thehashCodemethods directly. It uses them for some kind of modulo operation, using its own hashing method which obeys some nice mathematical properties.