Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class Main { public static <T> Collection<? extends T> split(Collection<? extends T> d, int n) { Collection<T> tmp = new ArrayList<>(); Iterator it = d.iterator(); int k = Math.max(0, n); while (it.hasNext() && k > 0) { tmp.add((T) it.next()); k--; } return tmp; } }