List集合分页
作者:互联网
List<String> stocks = new ArrayList<>();
for (int i=0;i<27;i++){
stocks.add(i+"");
}
int pageSize = 10; //设置每页数据为十条
int pageNumber = 1; //第几页
int start = (pageNumber - 1) * pageSize;
int count = stocks.size();
List<String> newStocks1 = stocks.subList(start,count-start>pageSize?start+pageSize:count);
System.out.println(newStocks1);
pageNumber = 2;
start = (pageNumber - 1) * pageSize;
List<String> newStocks2 = stocks.subList(start,count-start>pageSize?start+pageSize:count);
System.out.println(newStocks2);
pageNumber = 3;
start = (pageNumber - 1) * pageSize;
List<String> newStocks3 = stocks.subList(start,count-start>pageSize?start+pageSize:count);
System.out.println(newStocks3);
标签:count,分页,pageSize,List,start,pageNumber,集合,stocks 来源: https://www.cnblogs.com/summerJX/p/13973184.html