What is the (kind of) inverse operation to Java's Stream.flatMap()?

前端 未结 5 871
别那么骄傲
别那么骄傲 2021-02-19 05:40

The Stream.flatMap() operation transforms a stream of

a, b, c

into a stream that contains zero or more elements for each input el

5条回答
  •  清歌不尽
    2021-02-19 06:26

    You can hack your way around. See the following example:

    Stream> stream = Stream.of("Cat", "Dog", "Whale", "Mouse")
       .collect(Collectors.collectingAndThen(
           Collectors.partitioningBy(a -> a.length() > 3),
           map -> Stream.of(map.get(true), map.get(false))
        ));
    

提交回复
热议问题