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.
  • 91,686
  • 21
  • 171
  • 177
Angelo.Hannes
  • 1,729
  • 1
  • 18
  • 46

0 Answers0