Java List Truncate setSize(List list, int size)

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

Description

set Size

License

Open Source License

Declaration

public static void setSize(List<?> list, int size) 

Method Source Code

//package com.java2s;
/*//from   w  w w  .  ja  v  a2s. c  o  m
 * Copyright (c) 2012 The ANTLR Project. All rights reserved.
 * Use of this file is governed by the BSD-3-Clause license that
 * can be found in the LICENSE.txt file in the project root.
 */

import java.util.List;

public class Main {
    public static void setSize(List<?> list, int size) {
        if (size < list.size()) {
            list.subList(size, list.size()).clear();
        } else {
            while (size > list.size()) {
                list.add(null);
            }
        }
    }
}

Related

  1. setSize(L list, int newsize)
  2. trunc(List as, int length)
  3. truncate(final List list, final int newSize)
  4. truncate(final List items, final int limit)
  5. truncate(List list, int length)