
Inserts the element e at the beginning of the PriorityQueue. Inserts the element e at the end of an PriorityQueue. PriorityQueue ts2 = new PriorityQueue(new Comp()) Some important methods of PriorityQueue class Methods This constructor will create an empty PriorityQueue which is sorted according to the specified Comparator( comp) in constructor. This constructor example creates a PriorityQueue arrL2 initialized with the elements of a PriorityQueue arrL1. PriorityQueue arrL2 = new PriorityQueue(arrL1) PriorityQueue arrL1 = new PriorityQueue():

With a condition, that, Collection c holds similar type of objects as the type declared by the PriorityQueue. This constructor creates a PriorityQueue initialized with the elements of Collection c. This constructor example creates an empty PriorityQueue to hold Integer objects. This constructor creates an empty PriorityQueue of a particular type.

We can manually implement the Comparator interface to give a descending order to the elements of a PriorityQueue. itsĮlements are sorted in an ascending order which is automatically provided by its default Comparator interface, and PriorityQueue creates a priority-in, priority-out Queue i.e. The functionality of PriorityQueue has been enhanced. While Queue is a first-in, first-out( FIFO) queue of elements, PriorityQueue Class PriorityQueue is a generic collection class that extends AbstractQueue class and implements the Queue interface.
