How to sum values in a Map with a stream?

You can do this:

int sum = data.values().stream().mapToInt(Integer::parseInt).sum();

Leave a Comment