是否可以重命名一个Hashmap键? [英] Is it possible to rename a Hashmap key?
本文介绍了是否可以重命名一个Hashmap键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找重新命名Hashmap键的方法,但我不知道它是否可以在Java中使用。
尝试删除该元素,并将其重新命名为新名称。假设地图中的键是 String
,可以这样实现: Object obj = map.remove(oldKey);
map.put(newKey,obj);
I'm looking for a way to rename a Hashmap key, but i don't know if it's possible in Java.
解决方案
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屋!
查看全文