Joda-Time Sort Intervals

I have a list of Joda-Time Interval objects.

 List<Interval> intervals = new ArrayList<Interval>(); 

How can I sort the intervals at the beginning of the Date of each interval. Intervals do not overlap

+3
source share
2 answers

Just create a Comparator<Interval> that compares on startup time:

 public class IntervalStartComparator implements Comparator<Interval> { @Override public int compare(Interval x, Interval y) { return x.getStart().compareTo(y.getStart()); } } 

Then follow these steps:

 Collections.sort(intervals, new IntervalStartComparator()); 
+16
source

In your special case, collect launch moments using

 interval.getStart() 

in another list. DateTime using the Comparable interface, which sorts the list using Collections.sort(..) .

0
source

All Articles