关于list:java-List分页取值

34次阅读

共计 566 个字符,预计需要花费 2 分钟才能阅读完成。

/**
 * 利用 subList 办法进行分页
 *
 * @param list        分页数据
 * @param pagesize    页面大小
 * @param currentPage 以后页面
 */
private List pageBySubList(List list, int pagesize, int currentPage) {int totalcount = list.size();
    int pagecount = 0;
    List<String> subList;
    int m = totalcount % pagesize;
    if (m > 0) {pagecount = totalcount / pagesize + 1;} else {pagecount = totalcount / pagesize;}
    if (m == 0) {subList = list.subList((currentPage - 1) * pagesize, pagesize * (currentPage));
    } else {if (currentPage == pagecount) {subList = list.subList((currentPage - 1) * pagesize, totalcount);
        } else {subList = list.subList((currentPage - 1) * pagesize, pagesize * (currentPage));
        }
    }
    return subList;
}

正文完
 0