Java8学习笔记(十一)--并发与非并发流下reduce比较
BinaryOperator<Integer> operator = (l, r) -> l + r;
BiFunction<Integer, Integer, Integer> function = (l, r) -> l + r;
Integer reduce = Stream.of(1, 2, 3).parallel().reduce(3, function, operator);
// 15
System.out.println(reduce);
reduce = Stream.of(1, 2, 3).reduce(3, function, operator);
// 9
System.out.println(reduce);
reduce = Stream.of(1, 2, 3).reduce(3, operator);
// 9
System.out.println(reduce);
God, Grant me the SERENITY, to accept the things I cannot change,
COURAGE to change the things I can, and the WISDOM to know the difference.