Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static <T> List<List<T>> partition(List<T> inputList) { return partition(inputList, 1000); } public static <T> List<List<T>> partition(List<T> inputList, int size) { if (inputList.size() == 0) { return Collections.singletonList(inputList); } int partitions = inputList.size() / size + (inputList.size() % size > 0 ? 1 : 0); List<List<T>> result = new ArrayList<List<T>>(partitions); for (int i = 0; i < partitions - 1; i++) { result.add(inputList.subList(i * size, (i + 1) * size)); } result.add(inputList.subList((partitions - 1) * size, inputList.size())); return result; } }