Map中的TreeMap根据value排序
2017-08-16 17:16
375 查看
需要借助于Collections的sort(List list,Comparator
public static void main(String[] args) { Map<String, Integer> map=new TreeMap<>(); map.put("A", 30); map.put("B", 90); map.put("C", 80); map.put("D", 65); map.put("E", 89); map.put("F", 75); //对value进行排序 //将map.entrySet()转换为list集合 List<Map.Entry<String, Integer>> list= new ArrayList<>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() { @Override public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) { // TODO Auto-generated method stub return o1.getValue().compareTo(o2.getValue()); } }); for (Entry<String, Integer> entry : list) { System.out.println(entry.getKey()+"="+entry.getValue()); } }
相关文章推荐
- 【C++】map根据value排序
- java Map根据value排序
- map根据value排序
- TreeMap根据value排序
- 常用C/C++函数(文件夹遍历,Map根据Value排序)
- 取map容器的前10大(根据每一个value排序)元素
- 根据Map的value排序
- Map根据value排序
- java8 stream map根据value排序
- leetcode 387 map根据value排序
- leetcode 347 map根据value排序
- Map根据value排序
- 黑马程序员——Map集合:HashTable,HashMap,TreeMap
- List<Map>集合根据Map里的两个key值对List集合重新排序
- Java中对list map根据map某个key值进行排序的方法
- Map根据值排序
- scala基础41-Set/Map/TreeSet/TreeMap
- JAVA学习.JAVA集合类型Map.HashMap&TreeMap
- Java里多个Map的性能比较(TreeMap、HashMap、ConcurrentSkipListMap)
- C++ STL中Map的按Key排序跟按Value排序