Comment on Reduce operation in Java 8parentComments−ajanuary11yHaving a method allows sum to be written as: return listOfTxnAmounts.stream().reduce(BigDecimal.ZERO, BigDecimal::add); rather than what you have to do for operators(unless there is a way of referencing the operators I haven't found): return listOfTxnAmounts.stream().reduce(0, (a, b) -> a + b);−yarper11ySure, the other way is this; Arrays.stream(new int[] { 1,2,3 }).sum();
Comments
Having a method allows sum to be written as:
rather than what you have to do for operators(unless there is a way of referencing the operators I haven't found):Sure, the other way is this;