Here you can find the source of first_nItems(int n, Collection
public static <T> List<T> first_nItems(int n, Collection<T> fromList)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static <T> List<T> first_nItems(int n, Collection<T> fromList) { if (n >= fromList.size()) return new ArrayList<T>(fromList); return (new ArrayList<T>(fromList)).subList(0, n); }/*from w w w .j a v a 2 s . c o m*/ }