0

I have a list of items, say..

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

What I want is to have lists of size 3

[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14]]

How to do this with java streams?

list.stream()
    .reduce( /* what do I do here? */ )
    .forEach( l -> /* l.size() == 3 */);
Alexis C.
  • 87,500
  • 20
  • 164
  • 172
Angelo.Hannes
  • 1,689
  • 1
  • 17
  • 41

0 Answers0