Collections.sort()

Student s1=new Student();
s1.setClassid("1");
s1.setName("學生甲");
Student s2=new Student();
s2.setClassid("2");
s2.setName("學生乙");
Student s3=new Student();
s3.setName("學生丙");
s3.setClassid("3");
Listmlist=new ArrayList();
mlist.add(s1);
mlist.add(s2);
mlist.add(s3);
Collections.sort(mlist,new Comparator() {


@Override
public int compare(Student arg0, Student arg1) {
// TODO Auto-generated method stub
// return Integer.parseInt(arg0.getClassid())-Integer.parseInt(arg1.getClassid());
return -1;
}




} );

1为升序 -1为降序

System.out.println(mlist.toString());

你可能感兴趣的:(Android)