Split stream into substreams with N elements
问题 Can we somehow split stream into substreams with no more than N elements in Java? For example Stream<Integer> s = Stream.of(1,2,3,4,5); Stream<Stream<Integer>> separated = split(s, 2); // after that separated should contain stream(1,2), stream(3,4), stream(5) splitting by two streams solution is correct only for 2 streams, the same for N streams will be very ugly and write-only. 回答1: You can't split a Stream into 2 or more Streas s easily and directly. The only way the procedural one