Java Utililty Methods List Resize

List of utility methods to do List Resize

Description

The list of methods to do List Resize are organized into topic(s).

Method

voidresize(List list, int newSize)
resize
if (newSize < list.size()) {
    list.subList(newSize, list.size()).clear();
} else {
    list.addAll(Collections.nCopies(newSize - list.size(), null));
voidresize(List l, int n)
resize
if (l.size() > n) {
    while (l.size() > n) {
        l.remove(l.size() - 1);
} else {
    while (l.size() < n) {
        l.add(null);
voidresize(List list, int newSize, T newValue)
resize
if (list.size() <= newSize) {
    for (int i = 0; i < newSize - list.size(); i++) {
        list.add(newValue);
} else {
    for (int i = list.size() - 1; i > newSize; i--) {
        list.remove(i);
voidresize(List list, int size)
resize
while (list.size() > size)
    list.remove(list.size() - 1);
while (list.size() < size)
    list.add(null);