void (List<String> strings) { Map<Integer, Map<Character, Set<String>>> map = new HashMap<>(); for (String s : strings) { map.computeIfAbsent(s.length(), key -> new HashMap<>()).computeIfAbsent(s.charAt(0), k -> new HashSet<>()).add(s); } System.out.println(map); }