comparator(): This method is available in java.util.PriorityQueue class of Java.
Syntax:
Comparator<? super K> java.util.PriorityQueue.comparator()
This method returns the comparator used to order the elements in this queue, or null if this queue is sorted according to the natural ordering of its elements.
Parameters: NA
Returns: the comparator used to order this queue, or null if this queue is sorted according to the natural ordering of its elements.
Exceptions: NA
Approach
Java
import java.util.PriorityQueue;public class PriorityQueuecomparator {public static void main(String[] args) {PriorityQueue<Integer> priorityQueue =new PriorityQueue<Integer>();priorityQueue.add(12);priorityQueue.add(5);priorityQueue.add(10);priorityQueue.add(2);System.out.println(priorityQueue.comparator());}}
Output:
null
No comments:
Post a Comment