public void ensureCapacity ( long minCapacity ) { if ( array . length < minCapacity ) { //ensure minCapacity is < Integer.MAX_VALUE ErddapMath2 . ensureArraySizeOkay ( minCapacity , "StringArray" ) ; //caller may know exact number needed, so don't double above 2x current size int newCapacity = ( int ) Math . min ( Integer . MAX_VALUE - 1 , array . length + ( long ) array . length ) ; if ( newCapacity < minCapacity ) newCapacity = ( int ) minCapacity ; //safe since checked above String [ ] newArray = new String [ newCapacity ] ; System . arraycopy ( array , 0 , newArray , 0 , size ) ; array = newArray ; //do last to minimize concurrency problems } }
This ensures that the capacity is at least minCapacity .