Here you can find the source of splitList(List
public static <T> List<List<T>> splitList(List<T> sourceList, int spliTotal)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static <T> List<List<T>> splitList(List<T> sourceList, int spliTotal) { List<List<T>> resultList = new ArrayList<List<T>>(); int pagesize = spliTotal; int totalcount = sourceList.size(); int pagecount = 0; int m = totalcount % pagesize; if (m > 0) { pagecount = totalcount / pagesize + 1; } else {//from ww w . ja va2s . c om pagecount = totalcount / pagesize; } for (int i = 1; i <= pagecount; i++) { if (m == 0) { List<T> subList = sourceList.subList((i - 1) * pagesize, pagesize * (i)); resultList.add(subList); } else { if (i == pagecount) { List<T> subList = sourceList.subList((i - 1) * pagesize, totalcount); resultList.add(subList); } else { List<T> subList = sourceList.subList((i - 1) * pagesize, pagesize * (i)); resultList.add(subList); } } } return resultList; } }