public static void main(String[] args) {
HashMap<String, String> hashMap = new HashMap<>();
for (int i = 0; i < 6; i++) {
hashMap.put("key-" + i, "value-" + i);
}
printMap(hashMap);
HashMap<String, String> newMap = new HashMap<>();
Iterator<Map.Entry<String, String>> iterator = hashMap.entrySet().iterator();
Map.Entry<String, String> entry;
while (iterator.hasNext()) {
entry = iterator.next();
// 往newMap中放入新的Entry
newMap.put("prefix-" + entry.getKey(), entry.getValue());
// 删除老的Entry
iterator.remove();
}
System.out.println("结果:");
printMap(newMap);
}
https://blog.youkuaiyun.com/dustin_cds/article/details/79676286