download:Senior Architect of JAVA at Turing College

import java.util.Arrays;

import java.util.Collections;

import java.util.List;

public class ListPageUtil<T> {

/ / private int pageSize; / / private int pageCount; /** * private List<T> data; public ListPageUtil(List<T> data, int pageSize) { if (data == null || data.isEmpty()) { throw new IllegalArgumentException("data must be not empty!" ); } this.data = data; this.pageSize = pageSize; this.pageCount = data.size()/pageSize; if(data.size()%pageSize! =0){ this.pageCount++; Public List<T> getPagedList(int pageNum) {int fromIndex = public List<T> getPagedList(int pageNum) {int fromIndex = (pageNum - 1) * pageSize; if (fromIndex >= data.size()) { return Collections.emptyList(); } int toIndex = pageNum * pageSize; if (toIndex >= data.size()) { toIndex = data.size(); } return data.subList(fromIndex, toIndex); } public int getPageSize() { return pageSize; } public List<T> getData() { return data; } public int getPageCount() { return pageCount; } public static void main(String[] args) { Integer[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; List<Integer> list = Arrays.asList(array); ListPageUtil<Integer> pager = new ListPageUtil<Integer>(list, 10); System.out.println(pager.getPageCount()); List<Integer> page1 = pager.getPagedList(1); System.out.println(page1); List<Integer> page2 = pager.getPagedList(2); System.out.println(page2); List<Integer> page3 = pager.getPagedList(3); System.out.println(page3); }

}