标签:
1 private void grow( int minCapacity) { 2 // overflow-conscious code 3 int oldCapacity = elementData .length ; 4 int newCapacity = oldCapacity + (oldCapacity >> 1);//按1.5倍增长 5 if (newCapacity - minCapacity < 0) 6 newCapacity = minCapacity ; 7 if (newCapacity - MAX_ARRAY_SIZE > 0) 8 newCapacity = hugeCapacity( minCapacity ); 9 // minCapacity is usually close to size, so this is a win: 10 elementData = Arrays.copyOf( elementData , newCapacity ); 11 } 12 13 private static int hugeCapacity( int minCapacity) { 14 if (minCapacity < 0) // overflow 15 throw new OutOfMemoryError(); 16 return (minCapacity > MAX_ARRAY_SIZE) ? 17 Integer. MAX_VALUE : 18 MAX_ARRAY_SIZE ; 19 }
标签:
原文地址:http://www.cnblogs.com/wykCN/p/5857849.html