Java List Sub List subList(List list, int page, int size)

Here you can find the source of subList(List list, int page, int size)

Description

sub List

License

Open Source License

Declaration

public static List<?> subList(List<?> list, int page, int size) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    public static List<?> subList(List<?> list, int page, int size) {
        return list.subList(Math.min(list.size(), (page - 1) * size), Math.min(list.size(), size * page));

        //below doesn't work with java 1.8_32 due to java bug.
        /*//from  ww w  .j a va  2 s  .c  om
        return list.stream()
        .skip((page - 1)  * size)
        .limit(size)
        .collect(Collectors.toList());
        */
    }
}

Related

  1. subList(final List list, final int startIndex, final int endIndex)
  2. subList(final List source, final int... indices)
  3. sublist(LinkedHashSet base, int start, int count)
  4. subList(List list, int start, int end)
  5. subList(List list, int fromIndex, int toIndex)
  6. subList(List list, int fromIndex)
  7. subList(List list, int skip, int top)
  8. subList(List list, int start, int end)
  9. subList(List list, int begin, int end)