//声明
Map hashMap = new HashMap();
//向Map中添加数据
//.....
//转换
ArrayList> arrayList = new ArrayList>(
hashMap.entrySet());
//排序
Collections.sort(arrayList, new Comparator>() {
public int compare(Map.Entry map1,
Map.Entry map2) {
return (map2.getValue() - map1.getValue());
}
});
//输出
for (Entry entry : arrayList) {
System.out.println(entry.getKey() + "\t" + entry.getValue());
}
//声明
Map hashMap = new HashMap();
//向Map中添加数据
//.....
//转换
ArrayList> arrayList = new ArrayList>(hashMap.entrySet());
//排序
Collections.sort(arrayList, new Comparator>(){
public int compare(Map.Entry map1,
Map.Entry map2) {
return ((map2.getValue() - map1.getValue() == 0) ? 0
: (map2.getValue() - map1.getValue() > 0) ? 1
: -1);
}
});
//输出
for (Entry entry : arrayList) {
System.out.println(entry.getKey() + "\t" + entry.getValue());
}
//声明
Map hashMap = new HashMap();
//向Map中添加数据
//.....
//转换
ArrayList> arrayList = new ArrayList>(hashMap.entrySet());
//排序
Collections.sort(arrayList, new Comparator>(){
public int compare(Map.Entry map1,
Map.Entry map2) {
return ((map2.getValue() - map1.getValue() == 0) ? 0
: (map2.getValue() - map1.getValue() > 0) ? 1
: -1);
}
});
//输出
for (Entry entry : arrayList) {
System.out.println(entry.getKey() + "\t" + entry.getValue());
}
对Map中数据,按value值排序方法,布布扣,bubuko.com
原文:http://www.cnblogs.com/letters-zhang/p/3655109.html