对数数组中的内容强排序
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class TestComparator {
public static void main(String[] args){
ArrayList list = new ArrayList();
list.add(new Persion("lcl",28));
list.add(new Persion("fx",23));
list.add(new Persion("wqx",29));
Comparator comp = new Comparator(){
public int compare(Object o1,Object o2) {
Persion p1=(Persion)o1;
Persion p2=(Persion)o2;
if(p1.age<p2.age)
return 1;
else
return 0;
}
};
Collections.sort(list,comp);
for(int i=0;i<list.size();i++){
Persion p=(Persion) list.get(i);
System.out.println(p.age+"+"+p.name);
}
}
}