void (List<String> strings) { Map<Integer, DoubleSummaryStatistics> map = new HashMap<>(); for (String string : strings) { if (string != null) { map.computeIfAbsent(string.length(), k -> new DoubleSummaryStatistics()).accept(string.length()); } } System.out.println(map); }