criskgl
10/16/2019 - 9:49 AM

Build and Use CUSTOM COMPARATOR as class

private class myComparator implements Comparator<Interval> {
    @Override
    public int compare(Interval a, Interval b) {//things to compare
        //comparissons here.
        //1. if we want a to evaluate to left(go before) we return -1
        //2. if we want a to evaluate to right(go after) we return 1
        //3 .if we need to reevaluate for more ocnditions we return 0 
        //   and reevaluate steps 1 & 2 until we can return 1 or -1
        return a.start < b.start ? -1 : a.start == b.start ? 0 : 1;
    }
}
//usage:
Collections.sort(intervals, new myComparator());