1
我想排序日期列表,它不工作。Java日期排序使用分区
下面是声明和AttemptEntity
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "end_time")
private Date endTime;
public Date getEndTime() {
return endTime;
}
获取函数这里是没有做任何事情的排序代码。 GetAttempts()获取所有尝试调用的列表。他们不合适,我只是想能够得到任何有最新endTime的尝试。
List<AttemptEntity> attempts = called.getAttempts();
Collections.sort(attempts, new Comparator<AttemptEntity>() {
@Override
public int compare(AttemptEntity a1, AttemptEntity a2) {
if (a1.getEndTime() == null || a2.getEndTime() == null)
return 0;
return a1.getEndTime().compareTo(a2.getEndTime());
}
});
我相信,上面的代码应该那么它应该尝试进行排序后进行分类的尝试,并且,所以最晚结束时间将attempts.get(attempts.size() - 1).getEndTime()
我试图使用以下,并没有做任何分类。输入列表和输出列表完全相同。
Comparator<AttemptEntity> comparator = Comparator.comparing(AttemptEntity::getEndTime).reversed();
attempts.sort(comparator);
如果有没有'endTime'的尝试,它会被'compare'方法视为等于_every_其他实例。我不确定这样的通配符会对二进制排序过程产生什么影响。 – jingx