Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes. @return #items
(int additionalCapacity)
| 467 | * items to avoid multiple backing array resizes. |
| 468 | * @return {@link #items} */ |
| 469 | public T[] ensureCapacity (int additionalCapacity) { |
| 470 | if (additionalCapacity < 0) throw new IllegalArgumentException("additionalCapacity must be >= 0: " + additionalCapacity); |
| 471 | int sizeNeeded = size + additionalCapacity; |
| 472 | if (sizeNeeded > items.length) resize(Math.max(Math.max(8, sizeNeeded), (int)(size * 1.75f))); |
| 473 | return items; |
| 474 | } |
| 475 | |
| 476 | /** Sets the array size, leaving any values beyond the current size null. |
| 477 | * @return {@link #items} */ |