对Map中数据,按value值排序方法
来源:互联网 发布:apache nginx 编辑:程序博客网 时间:2024/06/05 06:37
1.Map<String,Integer>类型
//声明Map<String,Integer> hashMap = new HashMap<String,Integer>();//向Map中添加数据//.....//转换ArrayList<Entry<String, Integer>> arrayList = new ArrayList<Entry<String, Integer>>(hashMap.entrySet());//排序Collections.sort(arrayList, new Comparator<Map.Entry<String, Integer>>() {public int compare(Map.Entry<String, Integer> map1,Map.Entry<String, Integer> map2) {return (map2.getValue() - map1.getValue());}});//输出for (Entry<String, Integer> entry : arrayList) {System.out.println(entry.getKey() + "\t" + entry.getValue());}
2.Map<String,Float>类型
//声明Map<String,Float> hashMap = new HashMap<String,Float>();//向Map中添加数据//.....//转换ArrayList<Entry<String, Float>> arrayList = new ArrayList<Map.Entry<String,Float>>(hashMap.entrySet());//排序Collections.sort(arrayList, new Comparator<Map.Entry<String, Float>>(){public int compare(Map.Entry<String, Float> map1,Map.Entry<String,Float> map2) {return ((map2.getValue() - map1.getValue() == 0) ? 0: (map2.getValue() - map1.getValue() > 0) ? 1: -1);}});//输出for (Entry<String, Float> entry : arrayList) {System.out.println(entry.getKey() + "\t" + entry.getValue());}
3.Map<String,Double>类型
//声明Map<String,Double> hashMap = new HashMap<String,Double>();//向Map中添加数据//.....//转换ArrayList<Entry<String, Double>> arrayList = new ArrayList<Map.Entry<String,Double>>(hashMap.entrySet());//排序Collections.sort(arrayList, new Comparator<Map.Entry<String, Double>>(){public int compare(Map.Entry<String, Double> map1,Map.Entry<String,Double> map2) {return ((map2.getValue() - map1.getValue() == 0) ? 0: (map2.getValue() - map1.getValue() > 0) ? 1: -1);}});//输出for (Entry<String, Double> entry : arrayList) {System.out.println(entry.getKey() + "\t" + entry.getValue());}
- 对Map中数据,按value值排序方法
- 对Map中数据,按value值排序方法
- java.util.map中对value值排序
- C++中实现对map按照value值进行排序
- java对map中value的排序
- Map中按value值排序
- 对Map进行按值(value)排序
- Map 关于按对value进行排序
- 对Map按value进行排序
- java对Map按Value进行排序
- 根据value值对map进行排序
- 对map的value值排序
- Map四种获取key和value值的方法,以及对map中的元素排序
- Map四种获取key和value值的方法,以及对map中的元素排序
- Map四种获取key和value值的方法,以及对map中的元素排序
- Map对value进行排序
- 对map的value进行排序的方法
- 关于Map类型中对value进行排序的问题
- LINK : fatal error LNK1000: Internal error during IncrBuildImage
- 01_WEb应用开发概览
- sharepoint 2010 自定义列表数据的增删改查常用操作 server object model
- 2012全球最佳8个科技技术
- servlet和jsp初学总结2
- 对Map中数据,按value值排序方法
- linux开山-------------------韩顺平linux
- 备忘录模式
- 一个实体对象不能由多个 IEntityChangeTracker 实例引用 解决办法
- ssh与rsync简介
- 2012.12.24-2012.12.31
- C#.在vs2010中打开vs2012的项目
- 创建、结构、行为型设计模式类型归纳
- IOS 设置背景图片