编程语言
首页 > 编程语言> > java 集合根据某一属性进行排序

java 集合根据某一属性进行排序

作者:互联网

Collections.sort('传入你需要排序的集合;列如(List<TeacherAtten>)', new Comparator<TeacherAtten>() {
    @Override
public int compare(TeacherAtten o1, TeacherAtten o2) {
// 根据属性进行排序
if (Long.parseLong(o1.getTime().replaceAll("-","")) > Long.parseLong(o2.getTime().replaceAll("-",""))) {
return 1;
}
if (Long.parseLong(o1.getTime().replaceAll("-","")) == Long.parseLong(o2.getTime().replaceAll("-",""))) {
return 0;
}
return -1;
}
});

标签:java,getTime,parseLong,Long,某一,replaceAll,排序,o2,o1
来源: https://www.cnblogs.com/bt2882/p/11590434.html