list模擬 實現分頁
阿新 • • 發佈:2018-12-24
List<Student> list=new ArrayList<Student>(); list.add(new Student("xx", 12,"男")); list.add(new Student("qq", 18,"男")); list.add(new Student("aa", 20,"女")); list.add(new Student("cc", 10,"男")); list.add(new Student("dd", 14,"女")); list.add(new Student("ee", 14,"n")); list.add(new Student("ff", 15,"女")); //當前頁碼 int page=2; //每頁資料大小 int size=4; //獲取頁碼總數 if(list.size()%size!=0){ int Pagecount=(list.size()/size)+1; }else{ int Pagecount=(list.size()/size); } if (page*size<list.size()) { //按照每頁資料大小來獲取資料集合 System.out.println(list.subList((page-1)*size, page*size)); }else { //保證資料少於4的時候能夠獲取資料集合 System.out.println(list.subList((page-1)*size,list.size())); }