首页 > 其他分享 >对list集合进行分页

对list集合进行分页

时间:2022-09-19 11:37:09浏览次数:63  
标签:totalPage 分页 pageSize int list curentPage 集合 size

方法一:

    @Test
    public void test02(){
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
        int totalPage = 0;
        int pageSize = 5;
        int size = list.size();
        if (size % pageSize == 0) {
            totalPage = size / pageSize;
        } else {
            totalPage = (size / pageSize) + 1;
        }
        for(int i=1;i<=totalPage; i++){
            List<Integer> curentPage = null;
            if(i==totalPage){
                curentPage = list.subList((i-1)*pageSize, size);
            }else{
                curentPage = list.subList((i-1)*pageSize, i*pageSize);
            }
            System.out.println(curentPage.toString());
        }
    }

 

方法二:

1》导入maven依赖:

<dependency>
            <groupId>com.google.collections</groupId>
            <artifactId>google-collections</artifactId>
            <version>1.0</version>
</dependency>

 

2》调用 partition 方法,如下图:

 

 

 

 

标签:totalPage,分页,pageSize,int,list,curentPage,集合,size
From: https://www.cnblogs.com/mxggx/p/16707149.html

相关文章