我有两个HashMap的它看起来像这样,如何排序两个具有公共密钥的HashMap?
public HashMap<Integer, String> scoreName = new HashMap<Integer, String>();
public HashMap<Integer, Integer> scoreValue = new HashMap<Integer, Integer>();
这里既有的HashMap具有通用密钥。我想排序scoreValue HashMap和scoreName HashMap where scoreName HashMap也应该根据scoreValue进行排序。
实施例:
scoreValue = 5,1,7,7,9 scoreName排序scoreValue = 1,5,7,7,9后= A,B,C,d,E
排序scoreName = b,A,C,d,E
我可以整理我的scoreValue
List sortedKeys = new ArrayList(scoreValue.values());
Collections.sort(sortedKeys);
,但是这不是我要找的解决方案!
散列图没有排序。你想提取这些值并对它们进行排序吗? –
寻找不同的'Map'实现,它维护顺序。此外,保持密钥的排序。 –
我无法理解需要两张地图。 – Batty