Creating an Optional The Optional<T> class models the absence of a value by a special singleton returned by the Optional.empty()…
Flat Mapping Adapter for Downstream Collectors The flatMapping() method of the Collectors class encapsulates a mapper function and a downstream…
Numeric Optional Classes An instance of the generic Optional<T> class can only encapsulate an object. To deal with optional numeric…
Consumer Action on Stream Elements We have already used both the forEach() and forEachOrdered() terminal operations to print elements when…
Parallel Functional Reduction Parallel execution is illustrated in Figure 16.12. Multiple instances of the stream pipeline are executed in parallel,…
Counting Elements The count() operation performs a functional reduction on the elements of a stream, as each element contributes to…
Finding the First or Any Element The findFirst() method can be used to find the first element that is available…
We can again augment the accumulator with print statements as shown at (16) in Example 16.11. The output at (5)…
Collecting to a Set The method toSet() creates a collector that uses a mutable container of type Set to perform…
16.8 Collectors A collector encapsulates the functions required for performing reduction: the supplier, the accumulator, the combiner, and the finisher.…