February 2014
Beginner
1248 pages
62h 25m
English
Lines 45–48 of Fig. 17.5 create a stream pipeline that locates the even integers in an IntStream, sorts them in ascending order and displays each value followed by a space.
You filter elements to produce a stream of intermediate results that match a condition—known as a predicate. IntStream method filter (line 46) receives an object that implements the IntPredicate functional interface (package java.util.function). The lambda in line 46:
value -> value % 2 == 0
implements the interface’s test method, which receives an int and returns a boolean indicating whether the int satisfies the predicate—in this case, the IntPredicate returns true ...
Read now
Unlock full access