hashMap转换为list并排序

Iterator it = Names.keySet().iterator();
List tempList = new ArrayList();
while(it.hasNext()){
@SuppressWarnings("unchecked")
Map.Entry key =(Entry) it.next();
tempList.add(new KeyAndValue(key.getKey(), key.getValue()));
LogManager.e("key "+key.getKey() +" value "+key.getValue());
}

java.util.Collections.sort(tempList, new Comparator() {
@Override
public int compare(KeyAndValue object1, KeyAndValue object2) {
// TODO Auto-generated method stub
if (object1.value > object2.value) {
return -1;
} else if (object1.value< object2.value) {
return 1;
}
return 0;
}
});

转载于:https://www.cnblogs.com/zhenbeiju/archive/2012/08/03/2622234.html

你可能感兴趣的:(hashMap转换为list并排序)