先说结论:初始值设定大小为 cap = ( 需要存储的大小 / 负载因子 ) + 1
threshold :HashMap内部变量,若 元素数量 > threshold,则执行 resize
threshold 及 HashMap内部的变化步骤:
1. 执行 new HashMap(cap) 的构造器时,会执行 threshold = tableSizeFor(cap) 方法, threshold 会赋值为 cap 向上最近的 2的 n次方
2. 第一次put 元素的时候,会执行resize方法(实际没有rehash),仅执行 threshold = threshold * 负载因子(默认)
3.等到put元素的size大于 threshold 时, 会执行resize方法(这时方法内部执行了 rehash,性能损耗很大)。