I have a HashMap with some Keys - Values.
On some condition I want to update all values to single value regardless of keys.
Is there any util or predefined methods to do this, without for loop?
Any suggestions?
if (yourCondition) {
for (Map.Entry<String, String> entry : map.entrySet()) {
map.put(entry.getKey(), MY_VALUE);
}
}
Or for java 8 or higher (without a loop)
if (yourCondition) {
map.replaceAll( (k,v)->v=MY_VALUE );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With