在程序设计中,有数据库分页,往往由于特定的需求,需要对结果集List分页,下面看看怎么实现list分页吧。。。
package Test;
import java.util.ArrayList;
import java.util.List;
public class PageList {
/**
* 当前页码
*/
private int currentPage;
/**
* 总页数
*/
private int totalPage;
/**
* 总行数
*/
private int totalRows;
/**
* 每页显示条数
*/
private int avgRows = 5;
/**
* 原集合
*/
private List<String> list;
public PageList() {
super();
}
public PageList(int currentPage, int avgRows, List<String> list) {
super();
this.currentPage = currentPage;
this.avgRows = avgRows;
this.list = list;
this.totalRows = list.size();
this.totalPage = (this.totalRows - 1) / this.avgRows + 1;
}
public List<String> getPagerList() {
List<String> newList = new ArrayList<String>();
for(int i = (currentPage - 1) * avgRows; i < totalRows && i < currentPage * avgRows; i++) {
newList.add(list.get(i));
}
return newList;
}
}




