Characteristics of hashmap capacity expansion
The larger the loading factor, the higher the space utilization rate, and the more elements filled before expansion, the faster the put operation, but the linked list is easy to be too long, the higher the hash collision probability, the slower the get operation, the smaller the loading factor, the faster the get operation and the lower the hash collision probability, but the space utilization rate is low, and too many put elements will lead to frequent expansion and affect the performance.
When we use HashMap, if we know the approximate number of elements to be operated in advance, we'd better give an initialization value. First of all, we should try to avoid expansion. Secondly, we should set some values according to business scenarios and important parameters to improve the efficiency of use. HashMap doubles in size every time.