What's the neatest way to increment all values in a HashMap
by 1? The map is <String, Integer>
, but the key doesn't matter as every value will be incremented.
Is it "cleaner" to use lambdas with forEach
/compute
/etc. or just loop through the entries?
HashMap<String, Integer> map = mobCounter.get(mob);
for (Entry<String, Integer> e : map.entrySet()) {
map.put(e.getKey(), e.getValue() + 1);
}
This doesn't look too messy to me but I'm wondering if people like seeing lambdas more.
Map<String, Integer> map = mobCounter.get(mob);
instead ofHashMap
. \$\endgroup\$