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;
}
}
原文:https://www.cnblogs.com/connie313/p/12142680.html