对集合数据进行排序
首先寫一個類,繼承Comparator接口
如下:
public?class?SortCount?implements?Comparator<User>{
?
//@Override
public?int?compare(User?lhs,?User?rhs)?{
if(lhs.getCount()?!=?rhs.getCount())?{
return?lhs.getCount()?-?rhs.getCount();
}
else?{
return?(int)?(lhs.getDate()?-?rhs.getDate());
}
}
?
}
如果用戶不同,則按時間進行增加排序,列表越下面時間越大。
在代碼中進行調用:
Collections.sort(users,?new?SortCount());
即可對相關類按照具體的條件進行排序。
轉載于:https://www.cnblogs.com/kuaileyuyi/p/3853113.html
總結
- 上一篇: 关于这周工作中遇到的关于缓存问题的记录
- 下一篇: poj 3101 Astronomy (