Comparator.reverseOrder() vs Collections.reverseOrder()

Viewed 1125

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.

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.

Related