Here you can find the source of partition(List
public static <T> List<List<T>> partition(List<T> orig, int size)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static <T> List<List<T>> partition(List<T> orig, int size) { if (orig == null) { throw new NullPointerException("The list to partition must not be null"); }/*from ww w . j ava2 s .c o m*/ if (size < 1) { throw new IllegalArgumentException("The target partition size must be 1 or greater"); } int origSize = orig.size(); List<List<T>> result = new ArrayList<>(origSize / size + 1); for (int i = 0; i < origSize; i += size) { result.add(orig.subList(i, Math.min(i + size, origSize))); } return result; } }