void (List<String> strings) { final Map<Boolean, Map<Character, Set<String>>> nestedMap = strings.stream().collect(Collectors.partitioningBy((String s) -> s.length() > 2, Collectors.groupingBy(s -> s.charAt(0), Collectors.toSet()))); System.out.println(nestedMap); }