我正在搜索如何对列表中的元素进行排序,然后通过 getType 获取值 .. 如果 getType == 0 将 y 设置为列表中的第一个元素(但不替换 0 个位置中的项目。)其他人不需要按类型订购它们。
我在我的代码中做了两个比较。首先,我通过 getDate 订购了它们……其次,我通过 getType 订购了它们。但当然,我的方法返回的最后一个列表是按类型排序的列表。我不想要那个。
public List<PromotionList> returnSortedList(List<PromotionList> inputList) {
Collections.sort(inputList, (o1, o2) -> {
if (o1.getDate() != null) {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a", Locale.ENGLISH);
try {
return format.parse(o2.getDate()).compareTo(format.parse(o1.getDate()));
} catch (ParseException e) {
e.printStackTrace();
// Log.e("ErrorGetDate", e.getMessage());
return 0;
}
}
return 0;
});
Collections.sort(inputList, (o1, o2) -> {
if (o1.getType() != null && o2.getType() != null) {
if (o1.getPrioridad() == 0) {
int prior1 = o1.getType();
int prior2 = o2.getType();
return Integer.compare(prior1, prior2);
}
}
return 0;
return inputList;
}
谢谢。
手掌心
相关分类