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

前端 未结 5 878
别那么骄傲
别那么骄傲 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:11

        IntStream.range(0, 10)
                .mapToObj(n -> IntStream.of(n, n / 2, n / 3))
                .reduce(IntStream.empty(), IntStream::concat)
                .forEach(System.out::println);
    

    As you see elements are mapped to Streams too, and then concatenated into one large stream.

提交回复
热议问题