If I use a HashSet
with a initial capacity of 10 and a load factor of 0.5
then every 5 elements added the HashSet
will be increased or first the HashSet
is increased of 10 elements and after at 15 at 20 atc. the capacity will be increased?
Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).
The load factor is the measure that decides when to increase the capacity of the Map. The default load factor is 75% of the capacity. The threshold of a HashMap is approximately the product of current capacity and load factor. Rehashing is the process of re-calculating the hash code of already stored entries.
Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75). Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).
The load factor is a measure of how full the HashSet is allowed to get before its capacity is automatically increased. 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.
source
Default initial capacity of the HashMap takes is 16 and load factor is 0.75f (i.e 75% of current map size). The load factor represents at what level the HashMap capacity should be doubled.
For example product of capacity and load factor as 16 * 0.75 = 12. This represents that after storing the 12th key – value pair into the HashMap , its capacity becomes 32.
It's the second case. The loadFactor of both HashSet and hashMap is a relative factor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With