void (List<String> list) { Map<Boolean, Double> map1 = new HashMap<>(); map1.put(false, 0.0); map1.put(true, 0.0); for (String s : list) { map1.merge(s.isEmpty(), (double) s.length(), Double::sum); } System.out.println(map1); }