Java 8: preferred way to count iterations of a lambda?

后端 未结 11 1892
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 00:17

I face the same problem often. I need to count the runs of a lambda for use outside the lambda.

E.g.:

myStream.stream().filter(...).forEa         


        
11条回答
  •  忘了有多久
    2021-02-01 00:46

    reduce also works,you can use it like this

    myStream.stream().filter(...).reduce((item, sum) -> sum += item);
    

提交回复
热议问题