List<ResponseClient> responseClientListSelectedList = new ArrayList<>();
Collections.sort(responseClientListSelectedList, new Comparator<ResponseClient>() { @Override public int compare(ResponseClient o1, ResponseClient o2) { return 0; } });对List排序:常用的内部类实现比较器,但是是对日期排序,最初:
用int强转回丢失精度,所以用日期的比较方法:Collections.sort(responseClientListSelectedList, new Comparator<ResponseClient>() { @Override public int compare(ResponseClient o1, ResponseClient o2) { return (int)(o1.getCreateTime().getTime() - o2.getCreateTime().getTime()); } });
最后使用lambda表达式改:Collections.sort(responseClientListSelectedList, new Comparator<ResponseClient>() { @Override public int compare(ResponseClient o1, ResponseClient o2) { return o1.getCreateTime().compareTo(o2.getCreateTime()); } });
// 时间排序 Collections.sort(responseClientListSelectedList, (o1, o2) -> (o2.getCreateTime().compareTo(o1.getCreateTime())) );
List排序问题:根据list对象的创建时间排序,后用lambda表达式
最新推荐文章于 2023-03-30 00:35:05 发布