Here you can find the source of split(List
public static <V> ArrayList<List<V>> split(List<V> list, int divide)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static <V> ArrayList<List<V>> split(List<V> list, int divide) { int remain = list.size() % divide; int size = (list.size() - remain) / divide; ArrayList<List<V>> toReturn = new ArrayList<List<V>>(); for (int i = 0; i < divide; i++) { toReturn.add(i, new ArrayList<V>()); }// w w w. j av a 2 s. c o m for (List<V> iterSet : toReturn) { List<V> removed = new ArrayList<V>(); int toAdd = size; if (remain > 0) { remain--; toAdd++; } for (V obj : list) { if (toAdd == 0) { break; } iterSet.add(obj); removed.add(obj); toAdd--; } for (V obj : removed) { list.remove(obj); } } return toReturn; } }