I have String
and HashMap
like below codes:
Map<String, String> map = new HashMap<>();
map.put("ABC", "123");
String test = "helloABC";
map.forEach((key, value) -> {
test = test.replaceAll(key, value);
});
and I try to replace the string with the HashMap
values, but this doesn't work because test
is final and cannot be reassigned in the body of forEach
.
So are there any solutions to replace String
with HashMap
using Java 8 Stream API?