Do I really need to implement it myself?
private void shrinkListTo(ArrayList list, int newSize) {
for (int i = list.size() - 1; i >= newSi
use ArrayList#removeRange() method:
protected void removeRange(int fromIndex, int toIndex)
Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)
then use ArrayList#trimToSize() method:
Trims the capacity of this ArrayList instance to be the list's current size. An application can use this operation to minimize the storage of an ArrayList instance.