Java Reference
In-Depth Information
Figure 5.5. Incorrect use of map to find unique characters from a list of
words
Luckily there's a solution to this problem using the method flatMap! Let's see step by step how
to solve it.
Attempt using map and Arrays.stream
First, you need a stream of characters instead of a stream of arrays. There's a method called
Arrays.stream()that takes an array and produces a stream, for example:
String[] arrayOfWords = {"Goodbye", "World"};
Stream<String> streamOfwords = Arrays.stream(arrayOfWords);
Use it in the previous pipeline to see what happens:
 
Search WWH ::




Custom Search