1
날짜 목록을 정렬하려고하는데 작동하지 않습니다.Java 날짜순으로 컴 파트먼트를 사용하여 정렬
여기에 여기에 아무것도하지 않는 분류 코드는 선언하고
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "end_time")
private Date endTime;
public Date getEndTime() {
return endTime;
}
AttemptEntity
의 기능을 얻을. GetAttempts()는 호출 된 모든 시도 목록을 가져옵니다. 그들은 순서가 아니며, 나는 단지 최신 시도가있는 시도를 얻을 수 있기를 원합니다. .getEndTime() - 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());
}
});
나는 코드 (1 attempts.size을()) 위의 시도를 정렬해야하고, 다음 정렬되어야한다 시도 후, 그래서 최신 종료 시간 attempts.get 것이라고 믿는다
나는 아래의 것을 사용하려고 노력했는데, 그것도 전혀 정렬을하지 않았다. 입력 목록과 출력 목록은 완전히 동일합니다.
Comparator<AttemptEntity> comparator = Comparator.comparing(AttemptEntity::getEndTime).reversed();
attempts.sort(comparator);
'endTime'없이 시도가 있다면, 'compare' 메소드는 _every_ 다른 인스턴스와 동일하다고 간주됩니다. 바이너리 정렬 프로세스에 어떤 와일드 카드가 필요한지 잘 모르겠습니다. – jingx