Reputation: 123
When a HashMap is created its Initial Capacity will be 16, it means there will be 16 Buckets in memory where key value pair will be stored.
Now if implementation of my hashCode() in such a way that its generating random number in range of 1000 and 10000.
In this case how it is determined under which bucket this key value will be stored.?? How this random number in some range is transformed into Bucket number. ??
Upvotes: 2
Views: 773
Reputation: 1043
According to this article HOW DOES A HASHMAP WORK IN JAVA
All the keys with the same hash value are put in the same linked list (bucket). Keys with different hash values can end-up in the same bucket.
You may also want to check the answers from a similar question What is meant by number of buckets in the HashMap?
Upvotes: 2