【发布时间】:2022-11-03 04:20:06
【问题描述】:
例如,我想编辑此地图中 2 的键并将其设为 3,我该怎么做?
Map<Integer,Integer>map=new HashMap<>();
map.put(2,2);
map.get(2)=3;
【问题讨论】:
-
这回答了你的问题了吗? Is it possible to rename a Hashmap key?
标签: java dictionary
例如,我想编辑此地图中 2 的键并将其设为 3,我该怎么做?
Map<Integer,Integer>map=new HashMap<>();
map.put(2,2);
map.get(2)=3;
【问题讨论】:
标签: java dictionary
你不能。您必须使用旧键删除旧条目,并使用新键添加一个新条目,但值相同
Map<Integer,Integer>map=new HashMap<>();
map.put(2,2);
var removed = map.remove(2);
map.put(3, removed);
【讨论】: