Here you can find the source of split(Collection
public static <T> List<List<T>> split(Collection<T> orig, int batchSize)
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Main { public static <T> List<List<T>> split(Collection<T> orig, int batchSize) { if (orig == null || orig.isEmpty() || batchSize < 1) { return Collections.emptyList(); }/* ww w . jav a 2s. c o m*/ int size = orig.size(); int len = calSplitLen(batchSize, size); List<List<T>> result = new ArrayList<>(len); List<T> list = null; if (orig instanceof List) { list = (List<T>) orig; } else { list = new ArrayList<>(orig); } for (int i = 0; i < len; i++) { result.add(new ArrayList<>( list.subList(i * batchSize, ((i + 1) * batchSize) < size ? (i + 1) * batchSize : size))); } return result; } private static int calSplitLen(int batchSize, int size) { return ((size - 1) / batchSize) + 1; } }