Why filter() after flatMap() is “not completely” lazy in Java streams?

前端 未结 7 1165
误落风尘
误落风尘 2020-11-22 08:17

I have the following sample code:

System.out.println(
       \"Result: \" +
        Stream.of(1, 2, 3)
                .filter(i -> {
                             


        
7条回答
  •  情歌与酒
    2020-11-22 08:48

    Unfortunately .flatMap() is not lazy. However, a custom flatMap workaround is available here: Why .flatMap() is so inefficient (non lazy) in java 8 and java 9

提交回复
热议问题