List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
int page = 2;//相当于pageNo
int count = 20;//相当于pageSize
int size = list.size();
int pageCount=size/count;
int fromIndex = count * (page - 1);
int toIndex = fromIndex + count;
if (toIndex >= size) {
toIndex = size;
}
if(page>pageCount+1){
fromIndex=0;
toIndex=0;
}
System.out.println(list.subList(fromIndex, toIndex));
JAVA实现List分页
最新推荐文章于 2024-04-26 16:27:05 发布