Here you can find the source of partitionList(List
private static <T> List<List<T>> partitionList(List<T> list, final int partitionSize)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { /**/*from www . ja v a2 s .co m*/ * Partition a list into sublists of length L. The last list may have a size smaller than L.<br> * The sublists are backed by the original list. */ private static <T> List<List<T>> partitionList(List<T> list, final int partitionSize) { assert partitionSize > 0; assert list != null; final List<List<T>> res = new ArrayList<>(); for (int i = 0; i < list.size(); i += partitionSize) { res.add(list.subList(i, Math.min(list.size(), i + partitionSize))); } return res; } }