Java PriorityQueue.comparator()
Syntax
PriorityQueue.comparator() has the following syntax.
public Comparator <? super E> comparator()
Example
In the following code shows how to use PriorityQueue.comparator() method.
/* w ww. j a va 2 s. co m*/
import java.util.Comparator;
import java.util.PriorityQueue;
public class Main {
public static void main(String args[]) {
PriorityQueue<Integer> prq = new PriorityQueue<Integer>();
// insert values in the queue
prq.add(1);
prq.add(2);
prq.add(3);
prq.add(6);
prq.add(5);
System.out.println(prq);
// create comparator
Comparator comp = prq.comparator();
System.out.println ( "Comparator value is: "+ comp);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »