Search code examples
javaconceptual

HashMap Implementation Concept


I have read it many times, I just wanted to clarify.

HashMap is said as a Array of Arraylists.

Can we say that Array size is the bucket size for a hashmap

Note: I just want to make one correction:

1) No. of buckets is equivalent to Array size 2) Bucket size is the size of the Arraylist.

Sorry of the inconvenience. Please let me know if the above two points are correct.


Solution

  • No. In your analogy, each bucket would be one ArrayList, so the bucket size would be the size of the ArrayLists. A good implementation would strive to keep all of them roughly the same size, and fairly small.