I'm wondering if there is way with Java-Streams to group elements sequentially.
Let's say I'll have a simple IntStream from 1 to 1000:
IntStream streamTo1000 = IntStream.range(0, 1000);
Can I produce/convert this stream into a stream, that always groups together the next n-elements?
E.g., if I would like to collect always 3 elements together and process them further as one single item?
So, that I receive from the streamTo1000
a Stream that looks like
Stream.of(Arrays.asList(1,2,3), Arrays.asList(4,5,6), Arrays.asList(7,8,9), ...
Actually, it would be something like a reverse flatmap.
Could this be done with the available collect, reduce, grouping functions and/or can/should it be done with Stream.iterate?