聚合操作一定会使流关闭吗?
Topic source如果需要输出每次累加的结果,应将输出写在 reduce 的方法体里
Stream<Integer> sum1 = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
sum1.reduce(0, (acc, n) -> {
System.out.println(acc = acc + n);
return acc;
});
- 1
如果需要输出每次累加的结果,应将输出写在 reduce 的方法体里
Stream<Integer> sum1 = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
sum1.reduce(0, (acc, n) -> {
System.out.println(acc = acc + n);
return acc;
});
用户5273497715
如果我要对流进行后续的操作,比如这需要遍历输出,应该怎么做?