public static < T > T [ ] ensureCapacity ( final T [ ] oldElements , final int requiredLength ) { T [ ] result = oldElements ; if ( oldElements . length < requiredLength ) { result = Arrays . copyOf ( oldElements , requiredLength ) ; } return result ; }
Ensure an array has the required capacity . Resizing only if needed .