在Joda-Time中排序间隔 [英] Sort Intervals in Joda-Time
本文介绍了在Joda-Time中排序间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
推荐答案
只需创建一个比较器< Interval>
比较起始时间:
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());
}
}
然后使用它排序:
Collections.sort(intervals, new IntervalStartComparator());
这篇关于在Joda-Time中排序间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文