17.3.5 Intermediate Operation: Mapping

Lines 54–58 of Fig. 17.5 create a stream pipeline that locates the odd integers in an IntStream, multiplies each odd integer by 10, sorts the values in ascending order and displays each value followed by a space.

Intermediate Operation map

The new feature here is the mapping operation that takes each value and multiplies it by 10. Mapping is an intermediate operation that transforms a stream’s elements to new values and produces a stream containing the resulting elements. Sometimes these are of different types from the original stream’s elements.

IntStream method map (line 56) receives an object that implements the IntUnaryOperator functional interface (package java.util.function). The lambda in line ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.