What is the best way to transform and filter a Java Map using streams efficiently?

Instead of first converting values and then filtering in a second stream operation, you can apply both transformations within the same stream:

Map<String, Integer> output = input.entrySet().stream()
        .filter(e -> Integer.parseInt(e.getValue()) % 2 == 0) // Convert & filter at once
        .collect(Collectors.toMap(
                Map.Entry::getKey,
                e -> Integer.parseInt(e.getValue())
        ));

Why this works:

We parse and filter at the same time in .filter(), reducing the need for a second pass. We collect directly at the end, so .entrySet().stream() is only called once.