Here you can find the source of splitList(List
public static <T> List<List<T>> splitList(List<T> list, int page)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; public class Main { public static <T> List<List<T>> splitList(List<T> list, int page) { List<List<T>> listArray = new ArrayList<List<T>>(); Map<Integer, List<T>> maps = new HashMap<Integer, List<T>>(); int size = list.size(); for (int l = 0; l < page; l++) { maps.put(l, new ArrayList<T>()); }/*from www.j a va 2 s .c o m*/ if (size % page == 0) { for (int k = 0; k < size; k++) { maps.get(k % page).add(list.get(k)); } } else { for (int i = 0; i < size;) { for (int j = 0; j < page; j++) { if (i + page > size) { int left = size - i; for (int m = 0; m < left; m++) { maps.get(m).add(list.get(i)); i++; } } else { maps.get(j).add(list.get(i)); i++; } } } } Iterator<Integer> it = maps.keySet().iterator(); while (it.hasNext()) { listArray.add(maps.get(it.next())); } return listArray; } }