// "Replace Stream API chain with loop" "true" import java.util.*; public class Main { private static long test(Map> strings) { long count = 0L; for (Map.Entry> e : strings.entrySet()) { if (!e.getKey().isEmpty()) { String sInner = e.getKey(); for (String s : e.getValue()) { if (sInner.equals(s)) { count++; } } } } return count; } public static void main(String[] args) { Map> map = new HashMap<>(); map.put("", Arrays.asList("", "a", "b")); map.put("a", Arrays.asList("", "a", "b", "a")); map.put("b", Arrays.asList("", "a", "b")); map.put("c", Arrays.asList("", "a", "b")); System.out.println(test(map)); } }