Collections.sort(ar, new Comparator() {
@Override
public int compare(Intervals o1, Intervals o2) {
The Comparator and Comparable interface don't do any sorting, so there is no sorting algorithm there. They just compare two Objects, something you need if you want to sort a list of those objects.
Collections.sort() uses a variation of Timsort.
From the javadocs:
The implementation was adapted from Tim Peters's list sort for Python ( TimSort). It uses techiques from Peter McIlroy's "Optimistic Sorting and Information Theoretic Complexity", in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, January 1993.
Note that the Collections.sort()
algorithms gets a "black box" comparator, and uses the value it yields for each compare - without caring what is going on behind the scenes of the comparator.