java.lang.Object | |||
↳ | java.util.AbstractCollection <E> | ||
↳ | java.util.AbstractQueue <E> | ||
↳ | java.util.PriorityQueue<E> |
A PriorityQueue holds elements on a priority heap, which orders the elements according to their natural order or according to the comparator specified at construction time. If the queue uses natural ordering, only elements that are comparable are permitted to be inserted into the queue.
The least element of the specified ordering is the first retrieved with
poll()
and the greatest element is the last.
A PriorityQueue is not synchronized. If multiple threads will have to access
it concurrently, use the
PriorityBlockingQueue
.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Constructs a priority queue with an initial capacity of 11 and natural
ordering.
|
||||||||||
|
Constructs a priority queue with the specified capacity and natural
ordering.
|
||||||||||
|
Constructs a priority queue with the specified capacity and comparator.
|
||||||||||
|
Constructs a priority queue that contains the elements of a collection.
|
||||||||||
|
Constructs a priority queue that contains the elements of another
priority queue.
|
||||||||||
|
Constructs a priority queue that contains the elements of a sorted set.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Adds the specified object to the priority queue.
|
||||||||||
|
Removes all the elements of the priority queue.
|
||||||||||
|
Gets the comparator of the priority queue.
|
||||||||||
|
Gets the iterator of the priority queue, which will not return elements
in any specified ordering.
|
||||||||||
|
Inserts the element to the priority queue.
|
||||||||||
|
Gets but does not remove the head of the queue.
|
||||||||||
|
Gets and removes the head of the queue.
|
||||||||||
|
Removes the specified object from the priority queue.
|
||||||||||
|
Gets the size of the priority queue.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.AbstractQueue
|
|||||||||||
From class
java.util.AbstractCollection
|
|||||||||||
From class
java.lang.Object
|
|||||||||||
From interface
java.lang.Iterable
|
|||||||||||
From interface
java.util.Collection
|
|||||||||||
From interface
java.util.Queue
|
Constructs a priority queue with an initial capacity of 11 and natural ordering.
Constructs a priority queue with the specified capacity and natural ordering.
initialCapacity | the specified capacity. |
---|
IllegalArgumentException | if the initialCapacity is less than 1. |
---|
Constructs a priority queue with the specified capacity and comparator.
initialCapacity | the specified capacity. |
---|---|
comparator | the specified comparator. If it is null, the natural ordering will be used. |
IllegalArgumentException | if the initialCapacity is less than 1. |
---|
Constructs a priority queue that contains the elements of a collection. The constructed priority queue has the initial capacity of 110% of the size of the collection. The queue uses natural ordering to order its elements.
c | the collection whose elements will be added to the priority queue to be constructed. |
---|
ClassCastException | if any of the elements in the collection are not comparable. |
---|---|
NullPointerException | if any of the elements in the collection are null. |
Constructs a priority queue that contains the elements of another priority queue. The constructed priority queue has the initial capacity of 110% of the specified one. Both priority queues have the same comparator.
c | the priority queue whose elements will be added to the priority queue to be constructed. |
---|
Constructs a priority queue that contains the elements of a sorted set. The constructed priority queue has the initial capacity of 110% of the size of the sorted set. The priority queue will have the same comparator as the sorted set.
c | the sorted set whose elements will be added to the priority queue to be constructed. |
---|
Adds the specified object to the priority queue.
o | the object to be added. |
---|
ClassCastException | if the element cannot be compared with the elements in the priority queue using the ordering of the priority queue. |
---|---|
NullPointerException |
if
o
is
null
.
|
Gets the comparator of the priority queue.
Gets the iterator of the priority queue, which will not return elements in any specified ordering.
Inserts the element to the priority queue.
o | the element to add to the priority queue. |
---|
ClassCastException | if the element cannot be compared with the elements in the priority queue using the ordering of the priority queue. |
---|---|
NullPointerException |
if
o
is
null
.
|
Gets but does not remove the head of the queue.
Gets and removes the head of the queue.
Removes the specified object from the priority queue.
o | the object to be removed. |
---|
Gets the size of the priority queue. If the size of the queue is greater than the Integer.MAX, then it returns Integer.MAX.