Map<String,String> map = new TreeMap<String,String>(new Comparator<String>(){
public int compare(String obj1,String obj2){
//降序排序
return obj2.compareTo(obj1);
}
});
map.put("month", "The month");
map.put("bread", "The bread");
map.put("attack", "The attack");
//通过ArrayList构造函数把map.entrySet()转换成list
mappingList = new ArrayList<Map.Entry<String,String>>(map.entrySet());
//通过比较器实现比较排序
Collections.sort(mappingList, new Comparator<Map.Entry<String,String>>(){
public int compare(Map.Entry<String,String> mapping1,Map.Entry<String,String> mapping2){
return mapping1.getValue().compareTo(mapping2.getValue());
}
});
//通过ArrayList构造函数把map.entrySet()转换成list
mappingList = new ArrayList<Map.Entry<String,String>>(map.entrySet());
//通过比较器实现比较排序
Collections.sort(mappingList, new Comparator<Map.Entry<String,String>>(){
public int compare(Map.Entry<String,String> mapping1,Map.Entry<String,String> mapping2){
return mapping1.getKey().compareTo(mapping2.getKey());
}
});