I am stuck with a HashMap issue. I am trying to copy data from one HashMap to another.
Please excuse my syntax - this is just an example. I also tried looking at other examples but could not find anything for my usecase.
Lets say -
HashMap<String, String> hashMap1 = {(1, "New Value"), (2, "New Value")}
HashMap<String, String> finalHashMap = {(1, "None"), (2, "Blah"), (3, "Something else")}
This is the original code:
hashMap1.forEach(finalHashMap::putIfAbsent);
This is final output I want:
finalHashMap = {(1, "New Value"), (2, "Blah"), (3, "Something else")}
Note: 2 does not get overwritten because its value is not "None"
This works when Null or Empty case but not for None case :(
Can someone help me and modify code to help with "None" case as well?
I can do this traditional way, but trying to see if there is any one liner that I can use for this.