Advertisement

在Map中按值排序后获取最大值对应的键

阅读量:

一 相关知识

**** Map结构本质上是由键值对构成的集合,其中键(Key)本身是一个不重复的集合,而值(Value)则可以存在重复现象。

通常情况下,常用的子类包括HashMap和TreeMap,

若注重性能表现,则推荐使用HashMap,

若希望键具有排序特性,则应选择TreeMap。

二 按照Value的数值进行排序。(EntrySet+Comparator)

Map<String , Integer> mapInteger = new HashMap<String , Integer>();

mapInteger.put("A", 98);

mapInteger.put("B", 50);

mapInteger.put("C", 76);

++

mapInteger.put("D", 23);

++

mapInteger.put("E", 85);

++

对map中整型value进行排序的具体操作

全部评论 (0)

还没有任何评论哟~