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
Another alternative is to use apache commons MutableInt.
MutableInt cnt = new MutableInt(0); myStream.stream() .filter(...) .forEach(item -> { foo(); bar(); cnt.increment(); }); System.out.println("The lambda ran " + cnt.getValue() + " times");