书读的少你别骗我。。。hashmap源码  int capacity = 1 ; // 初始容量
14 while (capacity < initialCapacity) //确保容量为2的n次幂,使capacity为大于initialCapacity的最小的2的n次幂 15 capacity <<= 1; 16 17 this.loadFactor = loadFactor; 18 threshold = (int)(capacity * loadFactor); 19 table = new Entry[capacity]; 
  1. if  (numKeysToBeAdded > threshold) {  
  2.             // 重新计算新的容量先resize   
  3.             int  targetCapacity = ( int )(numKeysToBeAdded / loadFactor +  1 );  
  4.             if  (targetCapacity > MAXIMUM_CAPACITY)  
  5.                 targetCapacity = MAXIMUM_CAPACITY;  
  6.             int  newCapacity = table.length;  
  7.             while  (newCapacity < targetCapacity)  
  8.                 newCapacity <<= 1 ;  
  9.             if  (newCapacity > table.length)  
  10.                 resize(newCapacity);  

扩容为两倍,部位2N次补齐再两倍