【发布时间】:2021-06-05 20:34:42
【问题描述】:
例如。我有以下HashMap,如果我知道密钥'b',如何获取条目'b'=6。有什么办法吗?
Map<Character, Integer> map=new HashMap<>();
map.put('a',7);
map.put('b',6);
map.put('c',5);`
顺便说一句,我想这样做是因为所有这些条目都在优先级队列中。我必须从优先级队列中删除该条目并重新插入以确保它是有序的。
谢谢。
【问题讨论】:
-
我不明白。为什么一个简单的
get()电话不够用?例如。Character key = 'b'; Integer value = map.get(key); -
为什么要把k+v存入优先队列?最好只存储密钥。
标签: java dictionary hashmap