先說結論:初始值設定大小為 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,性能損耗很大)。