例子中List元素使用Hashtable中某键值排序为例!
private Comparator<Hashtable<String,Object>> comparator = new Comparator<Hashtable<String,Object>>(){
public int compare(Hashtable<String,Object> s1,Hashtable<String,Object> s2) {
int x1=new Integer((String)s1.get("f")).intValue();
int x2=new Integer((String)s2.get("f")).intValue();
return x2-x1;
}
};
使用:
Collections.sort(list,comparator);
其中 list 为要排序的List对象!
小小作品