map和flapmap最大的区别就是,map处理完以后,源数据和结果是1对1,flapmap处理完以后可能源数据和结果是1对多,
举例:
{"one", "two"} 使用map的split(""),返回{{"o", "n", "e"}, {"t","w", "o"}}, 输入2个对象,,输出也是2个对象, 每个输出的对象是一个String[]
{"one", "two"} 使用flapmap的split(""),返回{"o", "n", "e", "t", "w", "o"}, 输入2个对象,返回的是一个打平的数组,每个输入的对象,在这个数组里可能是多个对象
1 Java
String[] wordlist = {"one", "two"}; Stream<String> wordstream = Arrays.stream(wordlist); List list = wordstream.map(word -> word.split("")) .flatMap(Arrays::stream) .distinct() .collect(Collectors.toList()); System.out.println(list); [o, n, e, t, w]
标签:map,stream,对象,two,理解,split,flapmap From: https://www.cnblogs.com/chengxin1982/p/16910690.html