写了一个逻辑,把一个list拆分成指定大小的多个list
作者:互联网
/**
*
* @param list 需要拆分的list
* @param pageSize 每个list的大小
* @param <T>
* @return
*/
private <T> List<List<T>> splitList(List<T> list, int pageSize) {
int listSize = list.size();
int page = (listSize + (pageSize - 1)) / pageSize;
List<List<T>> listArray = new ArrayList<List<T>>();
for (int i = 0; i < page; i++) {
List<T> subList = new ArrayList<T>();
for (int j = 0; j < listSize; j++) {
int pageIndex = ((j + 1) + (pageSize - 1)) / pageSize;
if (pageIndex == (i + 1)) {
subList.add(list.get(j));
}
if ((j + 1) == ((j + 1) * pageSize)) {
break;
}
}
listArray.add(subList);
}
return listArray;
}
标签:分成,逻辑,pageSize,int,List,listSize,list,subList 来源: https://blog.csdn.net/XuYuanChong/article/details/91979129