February 2014
Beginner
1248 pages
62h 25m
English
You can define your own reductions for an IntStream by calling its reduce method as shown in lines 29–31 of Fig. 17.5. Each of the terminal operations in Section 17.3.2 is a specialized implementation of reduce. For example, line 31 shows how to sum an IntSteam’s values using reduce, rather than sum. The first argument (0) is a value that helps you begin the reduction operation and the second argument is an object that implements the IntBinaryOperator functional interface (package java.util.function). The lambda:
(x, y) -> x + y
implements the interface’s applyAsInt method, which receives two int values (representing the left and right operands of a binary operator) and performs a calculation with the values—in ...
Read now
Unlock full access