---------------------------------------------------------------------------------------------------------------------------------------------------------------------
java arrayList 根据其中一个属性排序问题
例子:根据创建时间排序
// 正序排列
Collections.sort(list, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
MessageDto stu1 = (MessageDto) o1;
MessageDto stu2 = (MessageDto) o2;
return stu1.getCreatedate().compareTo(stu2.getCreatedate());
}
});
return list;
// 倒序排列 比较时变换比较的位置
// Collections.reverse(list);
Collections.sort(list, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
MessageDto stu1 = (MessageDto) o1;
MessageDto stu2 = (MessageDto) o2;
return stu2.getCreatedate().compareTo(stu1.getCreatedate());
}
});
return list;