finalNode[]resize(){Node[]oldTabtable;intoldCap(oldTabnull)?0:oldTab.length;into final Node[] resize() { Node[] oldTab = table; int oldCap = (oldTab == null) ? 0 : oldTab.length; int oldThr = threshold; int newCap, newThr = 0; //如果有容量
finalNode[]resize(){Node[]oldTabtable;intoldCap(oldTabnull)?0:oldTab.length;into
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) 0) // initial capacity was placed in threshold newCap = oldThr; else { // zero initial threshold signifies using defaults newCap = DEFAULT_INITIAL_CAPACITY; newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); } if (newThr == 0) { float ft = (float)newCap * loadFactor; newThr = (newCap = DEFAULT_INITIAL_CAPACITY了,那么threshold也扩大两倍 */ if (oldTab != null) { //将原来map中非null的元素rehash之后再放到newTab里面去 for (int j = 0; j