What is the load factor of Hashmap in Java
In this tutorial we are going to learn about the load factor of Hashmap in detail.
HashMaps performance depends on two things i.e., first, initial capacity and second, load factor. Whenever we create Hashmap, initial capacity number of the bucket is created initially and load factor is the criteria to decide, when we have to increase the size of HashMap when its about to get full.
A load factor is the number that controls the resizing of HashMap. When a number of elements in the HashMap cross the load factor as if the load factor is 0.75 and when becoming more that 74% full then the resizing trigger which involves array copy.
The resizing happens when the map becomes full or when the size of the map crosses the load factor. If the load factor is 0.75 and then becomes more that 75% full, then resizing trigger which involves an array copy. First, the size of the bucket is doubled, and then old entries are copied into a new bucket.
The Capacity denotes how many times entries HashMap can store and size denotes how many mappings or key/value pair is currently present.