Here you can find the source of lazyPartition(final Stream
public static <T> Stream<Stream<T>> lazyPartition(final Stream<T> stream, final int maxPartitionSize)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.stream.Stream; import java.util.stream.StreamSupport; public class Main { public static <T> Stream<Stream<T>> lazyPartition(final Stream<T> stream, final int maxPartitionSize) { final Iterator<T> iterator = stream.iterator(); final Iterable<Stream<T>> partitionedIterable = () -> new Iterator<Stream<T>>() { public boolean hasNext() { return iterator.hasNext(); }/* ww w. j a v a 2 s. c o m*/ public Stream<T> next() { List<T> partition = new ArrayList<>(); while (partition.size() < maxPartitionSize && iterator.hasNext()) { partition.add(iterator.next()); } return partition.stream(); } }; return StreamSupport.stream(partitionedIterable.spliterator(), false); } }