Map<String,Double>map=new TreeMap<String,Double>();
map.put("mit", 3795104.300);
map.put("ramin", 6.155);
map.put("research", 889.159);
map.put("mix", 1.375);
map.put("gorgeou", 9.341);
map.put("shneiderman", 7.775);

List<Entry<String,Double>>lists=new ArrayList<Entry<String,Double>>(map.entrySet());
Collections.sort(lists,new Comparator<Map.Entry<String, Double>>() {
public int compare(Map.Entry<String, Double> o1,Map.Entry<String, Double> o2)
{
double q1=o1.getValue();
double q2=o2.getValue();
double p=q2-q1;
if(p>0){
return 1;
}
else if(p==0){
return 0;
}
else
return -1;
}
});
for(Map.Entry<String, Double> set:lists){
System.out.println(set.getKey() +" "+set.getValue());
}

posted on 2017-05-04 09:16  ALT_LB  阅读(5518)  评论(0编辑  收藏  举报