HashMap is implemented in a very nice way, but to understand how it is implemented, you need a genius. So, I read about HashMap in java docs. I have small questions regarding the HashMap :
- I know that the default
HashMap capacity is 16. In java documents they indicated the Initial default capacity - MUST be the power of two. . Any specific reason for this? - I know a little how
HashMap works based on HashCode, Bucket and LinkedList , if I'm not mistaken. Then the size of the HashMap increases. I mean how to manage the size of the buckets and the size of the LinkedList. - This may be a dumb question. When we add a new item to the
HashMap , based on the HashCode, it directly accesses that particular bucket without traveling like in LinkedList . I'm right? And another thing is that it does not add an element under the head to the tails. What is the reason for this. Added a new element in the LinkedList header that is present inside the bucket to avoid moving the tail. Am I correct?
source share