Java List Truncate truncate(List list, int length)

Here you can find the source of truncate(List list, int length)

Description

truncate

License

Open Source License

Declaration

public static void truncate(List<?> list, int length) 

Method Source Code


//package com.java2s;
/*/* w  ww .j ava2  s  . co m*/
 * Copyright (c) 2017, APT Group, School of Computer Science,
 * The University of Manchester. All rights reserved.
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import java.util.*;

public class Main {
    public static void truncate(List<?> list, int length) {
        while (list.size() > length) {
            list.remove(list.size() - 1);
        }
    }
}

Related

  1. setSize(L list, int newsize)
  2. setSize(List list, int size)
  3. trunc(List as, int length)
  4. truncate(final List list, final int newSize)
  5. truncate(final List items, final int limit)
  6. truncateEnd(List list, int numElements)
  7. truncateList(final List full, int maxSize)
  8. truncateList(int offset, int count, List originalList)
  9. truncateList(List input, int maxSize)