Why is the HashMap load factor 0.75

If the loading factor is large, the frequency of capacity expansion is low, the wasted space is small, and the probability of hash conflict is high. For example, when the loading factor is 1, the length of the Hashmap is 128, and the actual number of stored elements is between 64 and 128. During this period, hash conflicts occur frequently, resulting in a long list in the array, which affects performance.

If the loading factor is small, capacity expansion occurs more frequently, wastes more space, and hash conflicts are less likely to occur. For example, when the loading factor is 0.5, the length of hashMap is 128. When the number of hashMap reaches 65, expansion will be triggered. After expansion, only 65 of 256,256 are stored in principle, which is wasted.

After some synthesis, an average of 0.75 was taken as the loading factor. When the load factor is 0.75, poisson distribution formula is introduced. When the calculated length is 8, the probability =0.00000006, which is very small. When the length of the linked list is 8, it turns into a red-black tree.