【发布时间】:2020-09-16 12:54:21
【问题描述】:
我有一个如下的哈希图:
HashMap<String, Integer> hm = new HashMap<String, Integer>;
hm.put("a", 1);
hm.put("b", 12);
hm.put("c", 53);
hm.put("d", 2);
hm.put("e", 17);
hm.put("f", 8);
hm.put("g", 8);
如何获得具有 3 个最高值的键?所以它会返回:
"c", "e", "b"
谢谢。
【问题讨论】:
-
找到最大值,删除并重复两次?
-
迭代在 for 循环中设置的值。
-
如果你想订购你不应该首先使用哈希映射。使用有序映射,例如
TreeMap。
标签: java sorting hashmap entryset