What is the initial capacity of the HashMap when no size is defined, and how is it related to the number of entries it can ideally accommodate without resizing?

  • 16, and it can accommodate 16 entries.
  • 10, and it can accommodate 10 entries.
  • 32, and it can accommodate 32 entries.
  • The initial capacity is not defined, and it dynamically adjusts as entries are added.
In Java, when you create a HashMap without specifying an initial capacity, it defaults to an initial capacity of 16. This means that initially, the HashMap can accommodate 16 key-value pairs. However, as the number of entries increases and reaches a certain threshold (usually 75% of the capacity), the HashMap automatically resizes itself, doubling its capacity. So, option (a) is correct, with the explanation that it can ideally accommodate 16 entries initially but will resize when necessary.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *