/**
* @author hpj
*/
public class ListSubUtil {
/**
* 利用subList方法进行分页
* @param list 分页数据
* @param pagesize 页面大小 每页显示条数
* @param currentPage 当前页面 页码
*/
public static ListpageBySubList(List list, int currentPage, int pagesize) {
int totalcount = list.size();
int pagecount =0;
List subList;
int m = totalcount % pagesize;
if (m >0) {
pagecount = totalcount / pagesize +1;
}else {
pagecount = totalcount / pagesize;
}
if (m ==0) {
subList = list.subList((currentPage -1) * pagesize, pagesize * (currentPage));
}else {
if (currentPage == pagecount) {
subList = list.subList((currentPage -1) * pagesize, totalcount);
}else {
subList = list.subList((currentPage -1) * pagesize, pagesize * (currentPage));
}
}
return subList;
}
/*public static void main(String[] args) {
List list=new ArrayList();
list.add("aaa");
list.add("bbb");
list.add("ccc");
list.add("ddd");
list.add("eee");
list.add("fff");
List strings = ListSub.pageBySubList(list, 2, 2);
System.out.println(strings);
}*/
}