Here you can find the source of truncateList(List
List
.
Parameter | Description |
---|---|
list | the <code>List</code> |
len | the truncate length |
List
public static <T> List<T> truncateList(List<T> list, int len)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { /**/*from www.j a v a2 s. c om*/ * Returns a truncated version of the specified <code>List</code>. * @param list the <code>List</code> * @param len the truncate length * @return the truncated <code>List</code> */ public static <T> List<T> truncateList(List<T> list, int len) { if (len >= list.size()) return list; ArrayList<T> newList = new ArrayList<T>(len); for (int ii = 0; ii < len; ii++) { newList.add(list.get(ii)); } return newList; } }