I have list of Joda-Time Interval
objects.
List<Interval> intervals = new ArrayList<Interval>();
How can I sort the intervals on the beginning Date of each interval. The intervals are not overlapping
Just create a Comparator<Interval>
which compares by start times:
public class IntervalStartComparator implements Comparator<Interval> {
@Override
public int compare(Interval x, Interval y) {
return x.getStart().compareTo(y.getStart());
}
}
Then sort using that:
Collections.sort(intervals, new IntervalStartComparator());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With