Here you can find the source of setSize(List> list, int size)
public static void setSize(List<?> list, int size)
//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); } } } }