Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken.
(int newSize)
| 571 | /** Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is |
| 572 | * taken. */ |
| 573 | public void truncate (int newSize) { |
| 574 | if (newSize < 0) throw new IllegalArgumentException("newSize must be >= 0: " + newSize); |
| 575 | if (size <= newSize) return; |
| 576 | for (int i = newSize; i < size; i++) |
| 577 | items[i] = null; |
| 578 | size = newSize; |
| 579 | } |
| 580 | |
| 581 | /** Returns a random item from the array, or null if the array is empty. */ |
| 582 | public @Null T random () { |