Transform and filter a Java Map with streams
问题 I have a Java Map that I'd like to transform and filter. As a trivial example, suppose I want to convert all values to Integers then remove the odd entries. Map<String, String> input = new HashMap<>(); input.put("a", "1234"); input.put("b", "2345"); input.put("c", "3456"); input.put("d", "4567"); Map<String, Integer> output = input.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> Integer.parseInt(e.getValue()) )) .entrySet().stream() .filter(e -> e.getValue() % 2 == 0)