Here you can find the source of getFirstN(Collection
public static <E> List<E> getFirstN(Collection<E> objects, int n)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /**/*from w ww.ja v a 2 s.c om*/ * @return A new list with only n elements. */ public static <E> List<E> getFirstN(Collection<E> objects, int n) { if (objects == null) return null; List<E> newlist = new ArrayList<E>(); int i = 0; for (E item : objects) { if (i < n) newlist.add(item); else break; i++; } return newlist; } }