Mapping streams
Again, there are many new functional interfaces to be aware of; and again, thankfully, they follow a consistent naming pattern. Table 16.4 outlines the more common ones.
Table 16.4 - Mapping streams
In this table, the rows represent the source stream class and the columns represent the target stream class. Again, we use color to help organize our explanations. The yellow boxes represent situations where the source and target classes are the same. So, for example, if you are going from a DoubleStream
to another DoubleStream
, the method is map(DoubleUnaryOperator)
. The functional method is also listed - so for this example, DoubleUnaryOperator
‘s functional method is double applyAsDouble(double)
.
Let us examine the brown boxes. Each of these uses a mapToObj()
method as the source is a primitive stream and the target is a stream of objects. The source stream hints at the function to be used. For example, if the source is a DoubleStream...