Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; public class Main { public static <T> Collection<Collection<T>> split(Iterable<T> coll, int size) { if (size < 1) { return Collections.emptyList(); } final List<Collection<T>> ret = new ArrayList<>(); final Iterator<T> it = coll.iterator(); Collection<T> box = null; for (int i = 0; it.hasNext(); ++i) { if (i % size == 0) { if (box != null) { ret.add(box); } box = new ArrayList<>(size); } //noinspection ConstantConditions box.add(it.next()); } if (box != null) { ret.add(box); } return ret; } }