What is ProrityQueue ?

It extends AbstractQueue and implements Queue interface.
It creates a queue that is prioritized based on queue’s Comparator.
If no Comparator is specified when a ProirityQueue is constructed then the default Comparator will be used. The default Comparator will order the queue in ascending order.
import java.util.*;
class demo1
public static void main(String[] args){
PriorityQueue al=new PriorityQueue();

It represents a data structure to hold group of individual objects prior to processing based on some priority .it can be natural sorting order and it can be customized sorting order described by Comparator.
It is the implementation class of Queue interface.
• Insertion order is not preserved because here insertion is done based on some sorting order
• Duplicates are not allowed
• null insertion is not possible even as first element also
• If we are depending on natural sorting order Objects should be homogeneous violation leads to ClassCastException
• If we are depending on customized sorting order Objects can be heterogeneous also.

No comments:

Post a Comment