I made some PoCs to compare the performance of two types of implementation interacting list.
The fist one was using pure java using foreach
and checking with 'if' each element.
The second approach was using lambda
like this:
int max1 = lists1.stream()
.mapToInt(i -> i)
.max()
.getAsInt();
long finalCount = lists1.stream()
.filter(p -> p.intValue() == max1)
.count();
Obviously using lambda
was 5 time faster than using classic java foreach
.
I'm feeling very confidence to make mandatory to use a lambda
in my team in my current project like a rule, forbidding the use of classic java foreach
.
My questions is if exist some scenario that I cannot apply this rule (lambda required), I mean, if exist exception where I cannot use lambda
working with Collections.