1. arraylist soring

1) Collections.sort(al);

2) 

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

aa.sort(new Comparator<Integer>(){
@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;
}
}
posted on 2020-01-02 23:00  connie313  阅读(119)  评论(0编辑  收藏  举报