How to increment value for a specific key in a Map in java?
You could use compute (Java 8+):
m.compute(key, (k, v) -> v + 1);
I've always preferred to use a mutable int for these problems. So the code ends up looking like...
m.get(key).increment()
This avoids the unnecessary put overhead (which is small).