List <Map.Entry<String,Integer>> mapList = null;
mapList=new ArrayList<Map.Entry<String,Integer>>(myMap.entrySet());
//通过比较器实现比较排序
Collections.sort(mapList, new Comparator<Map.Entry<String,Integer>>(){
public int compare(Map.Entry<String,Integer> mapping1,Map.Entry<String,Integer> mapping2){
return mapping1.getValue().compareTo(mapping2.getValue());
}
});
for(Map.Entry<String,Integer> mapping:mapList){
output.write(mapping.getKey()+";"+mapping.getValue()+"\n");
System.out.println(number++);
}
java对Map按Value进行排序
最新推荐文章于 2024-06-06 11:24:10 发布