Java list pagination function implementation code example


This article mainly introduces the Java list pagination function code example, the article through the example code introduction is very detailed, has the certain reference study value to everybody’s study or the work, needs the friend may refer to

Today, due to the particularity of business, we need to get the data and paginate in Java code.

A tool class is written, which is recorded as follows:

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
 *JAVA memory paging tool class
public class JavaMemoryPageUtil {
   *Get paging data
   *@ param datalist the data collection for paging
   *What page is @ param pagenum
   *@ param PageSize how many items are displayed on each page
   * @return
  @SuppressWarnings({ "rawtypes", "unchecked" })
  public static List getPageLimit(List dataList, int pageNum, int pageSize){
      return dataList;
    List resultList = new ArrayList();
    //What is the number of items in all datalist data
    int currIdx = pageNum > 1 ? (pageNum -1) * pageSize : 0;
    for (int i = 0; i < pageSize && i < dataList.size() - currIdx; i++) {
      resultList.add(dataList.get(currIdx + i));
    return resultList;

The above is the whole content of this article, I hope to help you in your study, and I hope you can support developeppaer more.