How to get inverse of a comparator in java

前端 未结 4 1520
执念已碎
执念已碎 2021-01-18 01:07

In a method I receive a generic object E extends Comparable as an argument. Now i want to create two priority queues.One which uses the comparato

4条回答
  •  一整个雨季
    2021-01-18 01:26

    The single argument of Collections.reverseOrder is a Comparator and not a Collection. For your code simply use reverseOrder without an argument. You have to use a non-zero inital size, too. The following code will work.

    queue2=new PriorityQueue(1, Collections.reverseOrder());
    

提交回复
热议问题