JDK1.8中HashMap的resize()函数源码如何解析?
- 内容介绍
- 文章标签
- 相关推荐
本文共计415个文字,预计阅读时间需要2分钟。
javafinal Node[] resize() { Node[] oldTab=table; int oldCap=(oldTab==null) ? 0 : oldTab.length; int newCap, newThr=0; if (oldCap==0) { newCap=threshold; } else { newCap=oldCap < threshold) { newThr=threshold >>> 1; } } return newCap, newThr;}
final Node[] resize() { Node[] oldTab = table; int oldCap = (oldTab == null) ? 0 : oldTab.length; int oldThr = threshold; int newCap, newThr = 0; //如果有容量,说明该map已经有元素 if (oldCap > 0) { if (oldCap >= MAXIMUM_CAPACITY) { threshold = Integer.MAX_VALUE; return oldTab; } //在此处newCap = oldCap <<1,容量翻倍了 else if ((newCap = oldCap <<1)
本文共计415个文字,预计阅读时间需要2分钟。
javafinal Node[] resize() { Node[] oldTab=table; int oldCap=(oldTab==null) ? 0 : oldTab.length; int newCap, newThr=0; if (oldCap==0) { newCap=threshold; } else { newCap=oldCap < threshold) { newThr=threshold >>> 1; } } return newCap, newThr;}
final Node[] resize() { Node[] oldTab = table; int oldCap = (oldTab == null) ? 0 : oldTab.length; int oldThr = threshold; int newCap, newThr = 0; //如果有容量,说明该map已经有元素 if (oldCap > 0) { if (oldCap >= MAXIMUM_CAPACITY) { threshold = Integer.MAX_VALUE; return oldTab; } //在此处newCap = oldCap <<1,容量翻倍了 else if ((newCap = oldCap <<1)

