用ArrayList的subList方法做分頁


        List<Integer> beforeList= new ArrayList<>();
        for (int i = 0; i < 100 ; i++) {
            beforeList.add(i);
        }
        //假如有一個list,元素個數100
        int current=1; //頁碼
        int pageSize=10; //每頁顯示的數量

        int totalCount=beforeList.size();
        int pageCount = (totalCount / pageSize) + ((totalCount % current > 0) ? 1 : 0);

        int start=(current-1) * pageSize;
        int end = current==pageCount ? totalCount : current * pageSize;

        List<Integer> updateList=beforeList.subList(start,end);
        System.out.println(updateList);    

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM