![]() |
VOOZH | about |
The comparator() method of PriorityBlockingQueue returns the comparator that can be used to order the elements in a PriorityBlockingQueue. The method returns null value if the queue follows the natural ordering pattern of the elements. Syntax:
public Comparator<? super E> comparator()
Returns: This method returns the comparator set used to order the elements of the set in a specific order. It returns a null value if the PriorityBlockingQueue follows the default or natural ordering pattern. Below programs illustrate comparator() method of PriorityBlockingQueue: Example 1: To demonstrate comparator() method on PriorityBlockingQueue which contains a list of integers.
Comparator value: null PriorityBlockingQueuefollows natural ordering
Example 2: To demonstrate comparator() method on PriorityBlockingQueue which contains a list of integers.
Comparator value is: COMPARING@28d93b30 PriorityBlockingQueue follows: COMPARING@28d93b30 The elements after custom Comparator forGeeks, Geeks, A computer portal,