List<Integer> pageNumbers = new ArrayList<Integer>(); for (int i = 1; i <= totalPages; i++) { pageNumbers.add(i); }
int startIndex = (pageNumber - 1) * pageSize; int endIndex = startIndex + (pageSize - 1); int lastIndex = (listSize > 0) ? (listSize - 1) : 0;
    private GenericPair<List, List<Integer>> pageList(List listToPage, Integer pageNumber,            Integer pageSize, Comparator comparator) {        int listSize = listToPage.size();        int totalPages = (int) StrictMath.ceil(listSize / Double.valueOf(pageSize));        List<Integer> pageNumbers = new ArrayList<Integer>();        for (int i = 1; i <= totalPages; i++) {            pageNumbers.add(i);        }        int startIndex = (pageNumber - 1) * pageSize;        int endIndex = startIndex + (pageSize - 1);        int lastIndex = (listSize > 0) ? (listSize - 1) : 0;        if (endIndex > lastIndex) {            endIndex = lastIndex;        }        List sortedList = new ArrayList(listToPage);        Collections.sort(sortedList, comparator);        Collections.reverse(sortedList);        //must add 1 to endIndex, since subList excludes the final element        return new GenericPair<List, List<Integer>>(sortedList.subList(startIndex, endIndex+1),                pageNumbers);    }