Javatpoint Logo
Javatpoint Logo

Java PriorityQueue comparator() Method

The comparator() method of PriorityQueue() class returns the comparator that is used to order the elements of this queue, or returns null if the elements of this queue are sorted according to natural ordering.

Syntax

Return Value

The comparator() method returns the comparator that is used to order this queue, or returns null if this queue is sorted according to natural ordering.

Example 1

Test it Now

Output:

Comparator value is = null

Example 2

Test it Now

Output:

Ram got 98 marks.
Rahul got 19 marks.
Himanshu got 78 marks.
Geetanjali got 18 marks.

Comparator value is [email protected]
Next TopicJava PriorityQueue



Help Others, Please Share

facebook twitter pinterest