Java Reference
In-Depth Information
Figure 5.6. Using flatMap to find the unique characters from a list of
words
In a nutshell, the flatMap method lets you replace each value of a stream with another stream
and then concatenates all the generated streams into a single stream.
We come back to flatMap in chapter 10 when we discuss more advanced Java 8 patterns such as
using the new library class Optional for null checking. To solidify your understanding of map
and flatMap, try out Quiz 5.2 .
Quiz 5.2: Mapping
1. Given a list of numbers, how would you return a list of the square of each number? For
example, given [1, 2, 3, 4, 5] you should return [1, 4, 9, 16, 25].
Answer:
Search WWH ::




Custom Search