Java List Resize resize(List list, int size)

Here you can find the source of resize(List list, int size)

Description

resize

License

Open Source License

Declaration

public static <V> void resize(List<V> list, int size) 

Method Source Code

//package com.java2s;
/*/*from w  w  w .  jav a2  s  . c o  m*/
 * Copyright (C) 2009 Emweb bvba, Leuven, Belgium.
 *
 * See the LICENSE file for terms of use.
 */

import java.util.List;

public class Main {
    public static <V> void resize(List<V> list, int size) {
        while (list.size() > size)
            list.remove(list.size() - 1);
        while (list.size() < size)
            list.add(null);
    }

    public static <V> boolean add(List<V> list, V v) {
        if (list.indexOf(v) == -1) {
            list.add(v);
            return true;
        } else
            return false;
    }
}

Related

  1. resize(List list, int newSize)
  2. resize(List l, int n)
  3. resize(List list, int newSize, T newValue)