3가지 방법
Comparable
class Interval implements Comparable<Interval>{
int start;
int end;
Interval(int start,int end){
this.start=start;
this.end=end;
}
@Override
public int compareTo(Interval o) {
return this.start-o.start;
}
}
Comparator
Comparator<Interval> comparator = new Comparator<Interval>() {
@Override
public int compare(Interval o1, Interval o2) {
return o1.start - o2.start;
}
};
lambda
Collections.sort(intervalList, (a, b) -> b.start - a.start);