/** * New instance with sane defaults. * * @param expectedElements * The expected number of elements guaranteed not to cause buffer * expansion (inclusive). * * @param resizer * Underlying buffer sizing strategy. */ public ObjectArrayList(int expectedElements, ArraySizingStrategy resizer) { assert resizer != null; this.resizer = resizer; ensureCapacity(expectedElements); }
/** * Truncate or expand the list to the new size. If the list is truncated, the * buffer will not be reallocated (use {@link #trimToSize()} if you need a * truncated buffer), but the truncated values will be reset to the default * value (zero). If the list is expanded, the elements beyond the current size * are initialized with JVM-defaults (zero or <code>null</code> values). */ public void resize(int newSize) { if (newSize <= buffer.length) { if (newSize < elementsCount) { Arrays.fill(buffer, newSize, elementsCount, null); } else { Arrays.fill(buffer, elementsCount, newSize, null); } } else { ensureCapacity(newSize); } this.elementsCount = newSize; }
/** * New instance with sane defaults. * * @param expectedElements * The expected number of elements guaranteed not to cause buffer * expansion (inclusive). * * @param resizer * Underlying buffer sizing strategy. */ public ObjectArrayList(int expectedElements, ArraySizingStrategy resizer) { assert resizer != null; this.resizer = resizer; ensureCapacity(expectedElements); }
/** * Truncate or expand the list to the new size. If the list is truncated, the * buffer will not be reallocated (use {@link #trimToSize()} if you need a * truncated buffer), but the truncated values will be reset to the default * value (zero). If the list is expanded, the elements beyond the current size * are initialized with JVM-defaults (zero or <code>null</code> values). */ public void resize(int newSize) { if (newSize <= buffer.length) { if (newSize < elementsCount) { Arrays.fill(buffer, newSize, elementsCount, null); } else { Arrays.fill(buffer, elementsCount, newSize, null); } } else { ensureCapacity(newSize); } this.elementsCount = newSize; }