How can I update a Java HashMap with a new Map? I have a requirement where I have to iteratively update a HashMap with a subsequent new map I get.
Update has two parts
Currently, I am doing this
currentDataMap.forEach(finalMap::putIfAbsent);
finalMap.replaceAll(currentDataMap::getOrDefault);
Is there better way or one step way?
It sounds like all you need is a single call to putAll:
finalMap.putAll(currentDataMap)
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