zoukankan      html  css  js  c++  java
  • list 分页

    package com.jsz.peini.common.util;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class SubListUtil {
    
    public static List<Object> fenye(List list, int pagenum, int pagesize) {
    
    int totalcount = list.size();
    int pagecount = 0;
    int m = totalcount % pagesize;
    if (m > 0) {
    pagecount = totalcount / pagesize + 1;
    } else {
    pagecount = totalcount / pagesize;
    }
    
    // for(int i=1;i<=pagecount;i++){
    if (m == 0) {
    List<Object> subList = list.subList((pagenum - 1) * pagesize, pagesize * (pagenum));
    return subList;
    } else {
    if (pagenum == pagecount) {
    List<Object> subList = list.subList((pagenum - 1) * pagesize, totalcount);
    return subList;
    } else if (pagenum > pagecount) {
    return new ArrayList<Object>();
    } else {
    List<Object> subList = list.subList((pagenum - 1) * pagesize, pagesize * (pagenum));
    return subList;
    }
    
    // }
    }
    
    }
    
    public static void main(String[] args) {
    
    List<Object> list = new ArrayList<Object>();
    for (int i = 1; i < 52; i++) {
    list.add(i);
    }
    
    fenye(list, 10, 10);
    
    }
    }
     
     int pagenum, int pagesize  传过来参数的时候 这两个需要调换位置 懒得改方法
  • 相关阅读:
    analysis of algorithms
    Measurement of Reflected Radiation
    lecture 5
    lecture 3
    字符串
    Emission of Radiation辐射发射
    Electromagnetic Radiation(EMR) 电磁辐射
    Linux FTP服务器-VSFTPD虚拟用户配置
    jenkins notes
    python nose使用记录
  • 原文地址:https://www.cnblogs.com/xdcr/p/7274372.html
Copyright © 2011-2022 走看看