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);

参考:Java8新特性学习-Stream的Reduce及Collect方法详解

原文地址:https://www.cnblogs.com/yw0219/p/10590669.html