欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java

程序员文章站 2022-03-11 21:40:43
...
import java.util.ArrayList; 
import java.util.List; 
 
public class ListPagingTest { 
 
    public static void main(String[] args) { 
         
        List<Integer> list = new ArrayList<Integer>(); 
        for (Integer i = 0; i < 1000; i++) { 
            list.add(i); 
        } 
 
        int pageNumber = 50; // 每页记录数 
        int totalCount = list.size(); // 总记录数 
         
        int totalPage = totalCount / pageNumber; // 总页数 
        if((totalCount % pageNumber) > 0){ 
            totalPage += 1; 
        } 
         
        for (int pageNo = 0; pageNo < totalPage; pageNo++) { 
             
            int fromIndex = pageNo * pageNumber; 
             
            int toIndex = ((pageNo + 1) * pageNumber); 
            if(toIndex > totalCount){ 
                toIndex = totalCount; 
            } 
 
            for (Integer i : list.subList(fromIndex, toIndex)) { 
                System.out.println(i); 
            } 
        } 
         
    }