Q28: What are HashMap Capacity, Initial Capacity, and Load Factor?

  • Capacity: The number of buckets in the array (default 16).
  • Load Factor: Measure of how full the map gets before resizing (default 0.75).
  • Threshold: Calculated as $ ext{Capacity} imes ext{Load Factor}$ ($16 imes 0.75 = 12$). When total entries exceed threshold 12, capacity doubles to 32, and all entries are re-hashed (Rehash operation).
Key Takeaways
  • Default capacity = 16; Default load factor = 0.75; Default threshold = 12.
  • Resizing doubles capacity and re-hashes existing nodes.
Knowledge Check

When does a default HashMap (capacity 16, load factor 0.75) resize its bucket array?