import java.util.*; import java.util.function.Predicate; abstract class Test { public long countTweetsLongerThan(int numberOfChars, final List tweetList) { //numberOfChars = 100; //TODO uncomment to show it must be effectively final long totalByFor = 0; for (String tweet : tweetList) { if (tweet.length() > numberOfChars) { totalByFor++; } } final ArrayList guavaList = newArrayList(filter(tweetList, new Predicate() { @Override public boolean test(String tweet) { return false; } })); final long totalFromGuava = guavaList.size(); final long totalFromLambda = tweetList.stream() .filter(t -> t.length() > numberOfChars) .count(); if (totalByFor != totalFromLambda | totalByFor != totalFromGuava) { throw new RuntimeException(""); } return totalFromLambda; } abstract ArrayList newArrayList(Iterable elements); abstract ArrayList newArrayList(); abstract ArrayList newArrayList(E... elements); abstract Iterable filter(Iterable unfiltered, Predicate predicate); abstract Iterable filter(Iterable unfiltered, Class type); }