一文读懂HashMap和HashTable的区别以及常见面试题(32)


;

       modCount++;        //重新计算阀值
       threshold = (int)Math.min(newCapacity * loadFactor MAX_ARRAY_SIZE + 1);        //重新计算hashSeed
       boolean rehash = initHashSeedAsNeeded(newCapacity);

       table = newMap;        //将原来的元素拷贝到新的HashTable中
       for (int i = oldCapacity ; i-- > 0 ;) {            for (Entry<KV> old = oldMap[i
; old != null ; ) {
               Entry<KV> e = old;
               old = old.next;                if (rehash) {
                   e.hash = hash(e.key);
               
               int index = (e.hash & 0x7FFFFFFF) % newCapacity;

推荐阅读