long (Map<String, List<String>> strings) { long sum = 0L; for (Map.Entry<String, List<String>> e : strings.entrySet()) { if (!e.getKey().isEmpty()) { long count = e.getValue().stream().filter(new Predicate<>() { // we're inside anonymous class @Override public boolean test(String s) { return e.getKey().equals(s); } }).count(); sum += count; } } return sum; }