我有一个String并且想要替换其中的一些单词.我有一个HashMap关键是要替换的占位符和替换它的单词的值.这是我的老派代码:
private String replace(String text, Map<String, String> map) {
for (Entry<String, String> entry : map.entrySet()) {
text = text.replaceAll(entry.getKey(), entry.getValue());
}
return text;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将此代码编写为lambda表达式?
我尝试entrySet().stream().map(...).reduce(...).apply(...);但无法使其工作.
提前致谢.