# Priority Queue

#### PriorityQueue

• PriorityQueue is an implementation class of Queue Interface.
• It stores objects in ascending order based on some priority.
• It stores only Homogeneous elements which are of comparable type
• It does not permit Null values.

#### Constructor For the Class

Following are the constructor of the class :

• PriorityQueue() : Creates aPriorityQueuewith the default initial capacity (11) that orders its elements basis of natural ordering.
• PriorityQueue(Collection<? extendsE>c) :Creates a Priority Queue containing the elements in the specified collection.
• PriorityQueue(intinitialCapacity) :Creates a Priority Queue with the specified initial capacity that orders its elements based on their natural ordering.
• PriorityQueue(PriorityQueue<? extendsE>c) :Creates a Priority Queue containing the elements in the specified priority queue.
• Priority Queue(SortedSet<? extendsE>c) :Creates a PriorityQueue containing the elements in the specified sorted set.
• Priority Queue(intinitialCapacity, Comparator<? superE>comparator) :Creates a Priority Queue with the specified initial capacity that orders its elements according to the specified comparator.

#### Methods for the class:

• boolean add(E e) : This method inserts the specified element into this priority queue.
• void clear() : This method removes all of the elements from this priority queue.
• boolean contains(Object o) : This method returns true if this queue contains the specified element.
• Comparator<? super E> 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.
• Iterator<E> iterator() : This method returns an iterator over the elements in this queue.
• boolean offer(E e) : This method inserts the specified element into this priority queue.
• E poll(): This method retrieves and removes the head of this queue, or returns null if this queue is empty.
• E peek() : This method retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
• int size() :This method returns the number of elements in this collection.
• boolean remove(Object o) : This method removes a single instance of the specified element from this queue, if it is present.
• Object[] toArray() : This method returns an array containing all of the elements in this queue.
• <T> T[] toArray(T[] a) :This method returns an array containing all of the elements in this queue; the run time type of the returned array is that of the specified array.

```output:

***************************
queue size: 5
5
abhilash
bhavesh
hardik
rohit
vivek
null
***************************

```