Here you can find the source of resize(List> l, int n)
public static void resize(List<?> l, int n)
//package com.java2s; /* This file is part of the JFact DL reasoner Copyright 2011 by Ignazio Palmisano, Dmitry Tsarkov, University of Manchester This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ import java.util.List; public class Main { public static void resize(List<?> l, int n) { if (l.size() > n) { while (l.size() > n) { l.remove(l.size() - 1);/*from www . j a va 2s.co m*/ } } else { while (l.size() < n) { l.add(null); } } } public static <T> void resize(List<T> l, int n, T filler) { if (l.size() > n) { while (l.size() > n) { l.remove(l.size() - 1); } } else { while (l.size() < n) { l.add(filler); } } } }