- Java.util - WeakHashMap
- Java.util - Vector
- Java.util - UUID
- Java.util - TreeSet
- Java.util - TreeMap
- Java.util - TimeZone
- Java.util - TimerTask
- Java.util - Timer
- Java.util - StringTokenizer
- Java.util - Stack
- Java.util - SimpleTimeZone
- Java.util - ServiceLoader
- Java.util - Scanner
- Java.util - ResourceBundle.Control
- Java.util - ResourceBundle
- Java.util - Random
- Java.util - PropertyResourceBundle
- Java.util - PropertyPermission
- Java.util - Properties
- Java.util - PriorityQueue
- Java.util - Observable
- Java.util - Locale
- Java.util - ListResourceBundle
- Java.util - LinkedList
- Java.util - LinkedHashSet
- Java.util - LinkedHashMap
- Java.util - IdentityHashMap
- Java.util - Hashtable
- Java.util - HashSet
- Java.util - HashMap
- Java.util - GregorianCalendar
- Java.util - Formatter
- Java.util - EnumSet
- Java.util - EnumMap
- Java.util - Dictionary
- Java.util - Date
- Java.util - Currency
- Java.util - Collections
- Java.util - Calendar
- Java.util - BitSet
- Java.util - Arrays
- Java.util - ArrayList
- Java.util - ArrayDeque
- Java.util - Home
Java.util Package Extras
- Java.util - Discussion
- Java.util - Useful Resources
- Java.util - Enumerations
- Java.util - Exceptions
- Java.util - Interfaces
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java.util.PriorityQueue Class
Introduction
The java.util.PriorityQueue class is an unbounded priority queue based on a priority heap.Following are the important points about PriorityQueue −
The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used.
A priority queue does not permit null elements.
A priority queue relying on natural ordering also does not permit insertion of non-comparable objects.
Class declaration
Following is the declaration for java.util.PriorityQueue class −
pubpc class PriorityQueue<E> extends AbstractQueue<E> implements Seriapzable
Parameters
Following is the parameter for java.util.PriorityQueue class −
E − This is the type of elements held in this collection.
Class constructors
Sr.No. | Constructor & Description |
---|---|
1 | PriorityQueue() This creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering. |
2 | PriorityQueue(Collection<? extends E> c) This creates a PriorityQueue containing the elements in the specified collection. |
3 | PriorityQueue(int initialCapacity) This creates a PriorityQueue with the specified initial capacity that orders its elements according to their natural ordering. |
4 | PriorityQueue(int initialCapacity, Comparator<? super E> comparator) This creates a PriorityQueue with the specified initial capacity that orders its elements according to the specified comparator. |
5 | PriorityQueue(PriorityQueue<? extends E> c) This creates a PriorityQueue containing the elements in the specified priority queue. |
6 | PriorityQueue(SortedSet<? extends E> c) This creates a PriorityQueue containing the elements in the specified sorted set. |
Class methods
Sr.No. | Method & Description |
---|---|
1 | This method inserts the specified element into this priority queue. |
2 | This method removes all of the elements from this priority queue. |
3 | 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. |
4 | This method returns true if this queue contains the specified element. |
5 | This method returns an iterator over the elements in this queue. |
6 | This method inserts the specified element into this priority queue. |
7 | This method retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. |
8 | This method retrieves and removes the head of this queue, or returns null if this queue is empty. |
9 | This method removes a single instance of the specified element from this queue, if it is present. |
10 | This method returns the number of elements in this collection. |
11 | This method returns an array containing all of the elements in this queue. |
12 | This method returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array. |
Methods inherited
This class inherits methods from the following classes −
java.util.AbstractQueue
java.util.AbstractCollection
java.util.Object
java.util.Collection