java的 List 排序

来源:互联网 发布:方存乎见少的乎 编辑:程序博客网 时间:2024/04/30 04:29
Collections.sort(list, new Comparator<Student>(){                /*               * int compare(Student o1, Student o2) 返回一个基本类型的整型,               * 返回负数表示:o1 小于o2,               * 返回0 表示:o1和o2相等,               * 返回正数表示:o1大于o2。               */              public int compare(Student o1, Student o2) {                                //按照学生的年龄进行升序排列                  if(o1.getAge() > o2.getAge()){                      return 1;                  }                  if(o1.getAge() == o2.getAge()){                      return 0;                  }                  return -1;              }          });   

0 0