void (List<String> list) { Map<Integer, Integer> map3 = new HashMap<>(); for (String s : list) { String trim = s.trim(); map3.merge(s.length(), trim.length(), Integer::sum); } System.out.println(map3); }