java基础

1. arraylist soring

1) Collections.sort(al);

2) 

    public void stackSorting(String stk) {
// write your code here
ArrayList aa = new ArrayList();

aa.sort(new Comparator(){
@Override
public int compare(int arg0, int arg1){
return aa.get(arg0).compareTo(aa.get(arg1));
}
});

}
}
class SortByAge implements Comparator {
public int compare(Object o1, Object o2) {
Student s1 = (Student) o1;
Student s2 = (Student) o2;
return s1.getAge().compareTo(s2.getAge());
// if (s1.getAge() > s2.getAge())
// return 1;
// return -1;
}
}

你可能感兴趣的:(java基础)