About
A hash map is an implementation of a map that stores the data in buckets.
The distribution of the data to a bucket is via the hash value of the key map entry (hence a HashMap).
Articles Related
Usage
A hash map is used
Performance
- This structure provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Hash-Maps are hard to beat in performance for key-based lookups.
- Iteration over collection views requires time proportional to:
- the capacity of the HashMap instance (the number of buckets)
- plus its size (the number of key-value mappings).
Properties
Capacity
- capacity: The capacity is the number of buckets in the hash table.
Load factor
The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased.
A load factor of .75 offers a good tradeoff between time and space costs.
When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets.