结论:区别在与返回类型不同,map返回泛型R,flatMap返回流。
<R> Stream<R> map(Function<? super T, ? extends R> mapper);<R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper);
flatMap使用方式:
List<Integer> integers = Arrays.asList(1, 2, 3);
List<String> collect = integers.stream().flatMap(i -> Stream.of((i + "1").split(""))).collect(Collectors.toList());
collect.forEach(System.out::println);