Here you can find the source of divideListInSublistsOfNSize(List
public static <T> List<List<T>> divideListInSublistsOfNSize(List<T> list, int n)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static <T> List<List<T>> divideListInSublistsOfNSize(List<T> list, int n) { final List<List<T>> container = new ArrayList<>(); List<T> cList = new ArrayList<>(); for (T o : list) { cList.add(o);//from w w w . j a v a 2 s . c o m if (cList.size() == n) { container.add(cList); cList = new ArrayList<>(); } } if (cList != null && cList.size() > 0) { container.add(cList); } return container; } }