public class ListTest {
public static void main(String[] args) {
List<Integer> datalist = new ArrayList<Integer>();
for(int i=0;i<103;i++){
datalist.add(i);
}
//对数据进行切割,每一百条切割一次
List<List<Integer>> list = splitList(datalist, 100);
for(int i=0;i<list.size();i++){
System.out.println("第"+(i+1)+"段长度为:"+list.get(i).size());
}
}
/**
* 分割List
* @author bianrx
* @param list 待分割的list
* @param pageSize 每段list的大小
* @return List<<List<T>>
*/
public static <T> List<List<T>> splitList(List<T> list, int pageSize) {
List<List<T>> listArray = new ArrayList<List<T>>();
List<T> subList = null;
for (int i = 0; i < list.size(); i++) {
if (i % pageSize == 0) {//每次到达页大小的边界就重新申请一个subList
subList = new ArrayList<T>();
listArray.add(subList);
}
subList.add(list.get(i));
}
return listArray;
}
}