Skip to content

Instantly share code, notes, and snippets.

@PierreBtz
Last active August 29, 2015 14:22
Show Gist options
  • Save PierreBtz/09ecb01545d6c0bccf80 to your computer and use it in GitHub Desktop.
Save PierreBtz/09ecb01545d6c0bccf80 to your computer and use it in GitHub Desktop.
public static <T> void trim(List<T> list, int newSize) {
Preconditions.checkArgument(newSize >= 0, "Cannot trim the provided list to a negative size");
int size = list.size();
list.subList(Math.min(newSize, size), size).clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment