import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class StreamPagination {
public static void main(String[] args) {
List data = IntStream.rangeClosed(1, 100).boxed().collect(Collectors.toList());
List pageData = getPageData(data, pageSize, pageNumber);
List pageData1 = data.stream()
.skip((pageNumber - 1) * pageSize)
.collect(Collectors.toList());
System.out.println("第" + pageNumber + "页的数据:" + pageData);
public static List getPageData(List data, int pageSize, int pageNumber) {
int fromIndex = (pageNumber - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, data.size());
return data.subList(fromIndex, toIndex);