Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparator.reverseOrder() vs Collections.reverseOrder()

Is there a difference between the two? If so, what is it?

When I used them for a priority queue, the both sort it the same way.

like image 994
timg Avatar asked Mar 03 '23 14:03

timg


1 Answers

If you use a good IDE, it's very easy to see the source code of the Java Runtime Library methods. E.g. in Eclipse you press F3 when cursor is on the method.

If you do that on the Comparator.reverseOrder() method, you'll see:

public static <T extends Comparable<? super T>> Comparator<T> reverseOrder() {
    return Collections.reverseOrder();
}

Conclusion: They are exactly the same.

like image 184
Andreas Avatar answered Mar 05 '23 17:03

Andreas