public static void main(String[] args){
Map<String,String> setToneMoneyMap = new HashMap<String,String>();
setToneMoneyMap.put("1","75");
setToneMoneyMap.put("2","2");
setToneMoneyMap.put("3","78");
setToneMoneyMap.put("4","12");
setToneMoneyMap.put("5","1212");
List<Map.Entry<String,String>> list = new ArrayList<>(setToneMoneyMap.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String,String>>() {
public int compare(Map.Entry<String,String> o1, Map.Entry<String,String> o2) {
int compare = (Double.valueOf(o1.getValue())).compareTo(Double.valueOf(o2.getValue()));
//降序添加负号,升序不加负号
return -compare;
}
});
for (Map.Entry<String,String> entry : list) {
System.out.println("key: "+entry.getKey()+" value: "+entry.getValue());
}
}