是否可以重命名 Hashmap 键? [英] Is it possible to rename a Hashmap key?
本文介绍了是否可以重命名 Hashmap 键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种重命名 Hashmap 键的方法,但我不知道在 Java 中是否可行.
I'm looking for a way to rename a Hashmap key, but i don't know if it's possible in Java.
推荐答案
尝试删除元素,然后用新名称重新放置.假设地图中的键是 String
,可以这样实现:
Try to remove the element and put it again with the new name. Assuming the keys in your map are String
, it could be achieved that way:
Object obj = map.remove("oldKey");
map.put("newKey", obj);
这篇关于是否可以重命名 Hashmap 键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文