package test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test3 {
/*
* List<Map>的排序
*/
public static void main(String[] args) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for(int i=10; i>=0; i--) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("key", i);
list.add(map);
}
System.out.println(list);
Comparator<Map<String, Object>> comp = new Comparator<Map<String, Object>>() {
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
return o1.get("key").toString().compareTo(o2.get("key").toString());
}
};
Collections.sort(list, comp);
System.out.println(list);
}
}