Java 8 Stream with batch processing

For completeness, here is a Guava solution.

Iterators.partition(stream.iterator(), batchSize).forEachRemaining(this::process);

In the question the collection is available so a stream isn’t needed and it can be written as,

Iterables.partition(data, batchSize).forEach(this::process);

Leave a Comment