나는 Joda-TimeInterval
의 목록을 가지고 있습니다.Joda-Time의 정렬 간격
List<Interval> intervals = new ArrayList<Interval>();
각 간격의 시작 날짜에 어떻게 간격을 정렬 할 수 있습니까? , 당신의 특별한 경우
Collections.sort(intervals, new IntervalStartComparator());
나는 Joda-TimeInterval
의 목록을 가지고 있습니다.Joda-Time의 정렬 간격
List<Interval> intervals = new ArrayList<Interval>();
각 간격의 시작 날짜에 어떻게 간격을 정렬 할 수 있습니까? , 당신의 특별한 경우
Collections.sort(intervals, new IntervalStartComparator());
interval.getStart()
다른 목록입니다. DateTime
Comparable
인터페이스를 사용하면 Collections.sort(..)
을 사용하여 목록을 정렬 할 수 있습니다.
public class IntervalStartComparator implements Comparator<Interval> {
@Override
public int compare(Interval x, Interval y) {
return x.getStart().compareTo(y.getStart());
}
}
: 간격은 그냥 시작 시간으로 비교하는 Comparator<Interval>
을 만들
시작 시간을 정렬하지만 시작 시간을 기준으로 * 간격 *을 정렬하지 않습니다. –
@ 존 키 스케 (JonSkeet) : 당신의 해결책은 실제로 훨씬 더 좋습니다 :-) - 나는 더 조심스럽게 질문을 읽어야합니다 ... –
빠른 속도입니다. 감사합니다 – kozla13