void (List<String> list) { Map<Integer, Integer> map3 = list.stream().collect(Collectors.groupingBy(String::length, Collectors.mapping(String::trim, Collectors.summingInt(String::length)))); System.out.println(map3); }