我String和HashMap像下面的代码:
Map<String, String> map = new HashMap<>();
map.put("ABC", "123");
String test = "helloABC";
map.forEach((key, value) -> {
test = test.replaceAll(key, value);
});
Run Code Online (Sandbox Code Playgroud)
我尝试用HashMap值替换字符串,但这不起作用,因为test是最终的,不能在正文中重新分配forEach.
那么,有没有任何解决方案,以取代String与HashMap使用Java 8个流API?