Reset all values in hashmap without iterating?

hashmap, java

Solution

You can't avoid iterating in some fashion.

You could get the values via Map.values() and iterate over those. You'll bypass the lookup by key and it's probably the most efficient solution (although I suspect generally that would save you relatively little, and perhaps it's not the most obvious to a casual reader of your code)

Problem

I am trying reset all values in a `HashMap` to some default value if a condition fails. Currently i am doing this by iterating over all the keys and individually resetting the values. Is there any possible way to set a same value to all the keys without iterating? Something like: ``` hm.putAll("some val") //hm is hashmap object ```

Original source