Reputation: 5708
I have a HashMap and want to change the value (which is a string) by appending another string "hello".
HashMap<User, String> all = new HashMap<>();
mymap.forEach((k, v) -> v = v + " hello");
However, it does not work, "mymap" is unchanged. What is wrong?
Upvotes: 10
Views: 8550
Reputation: 28183
This is the job for Map#replaceAll
:
mymap.replaceAll((k, v) -> v + " hello");
Upvotes: 18