@Test
public void testFlatMap() {
List<String> words = Arrays.asList("hellow","world","world");
words.stream().map(w ->w.split("")).map(Arrays::stream).distinct().collect(Collectors.toList());
System.out.println(words);
List<String> wordList = words.stream()
.map(w ->w.split(""))
.flatMap(Arrays::stream).distinct().collect(Collectors.toList());
System.out.println(wordList);
}
-------------------------------控制台打印-----------------------
[hellow, world, world]
[h, e, l, o, w, r, d]
------------------------------------------------------------------
map的内部执行图
flatMap的内部执行图
map和flatMap中distinct的区别?