Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.List; import com.google.common.collect.Lists; public class Main { /** * Return the first N items in a collection. * */ public static <T> List<T> head(Collection<T> input, int count) { List<T> result = Lists.newArrayList(); ArrayList<T> tmp = Lists.newArrayList(); tmp.addAll(input); for (int i = 0; i < input.size(); i++) { if (result.size() == count) break; result.add(tmp.get(i)); } return result; } }