Java Reference
In-Depth Information
•
PriorityQueue()
createsa
PriorityQueue
instancewithaninitialca-
pacityof11elements,andwhichordersitselementsaccordingtotheirnatural
ordering.
•
PriorityQueue(Collection<? extends E> c)
createsa
Prior-
ityQueue
instance containing
c
's elements. If
c
is a
SortedSet
or
Pri-
orityQueue
instance, this priority queue will be ordered according to the
same ordering. Otherwise, this priority queue will be ordered according to the
naturalorderingofitselements.Thisconstructorthrows
ClassCastExcep-
tion
when
c
's elements cannot be compared to one another according to the
priority queue's ordering, and
NullPointerException
when
c
or any of
its elements contain the null reference.
•
PriorityQueue(int initialCapacity)
creates a
Prior-
ityQueue
instance with the specified
initialCapacity
, and which or-
ders its elements according to their natural ordering. This constructor throws
IllegalArgumentException
when
initialCapacity
is less than 1.
•
PriorityQueue(int initialCapacity, Comparator<? super
E> comparator)
creates a
PriorityQueue
instance with the specified
initialCapacity
,andwhichordersitselementsaccordingtothespecified
comparator
.Naturalorderingisusedwhen
comparator
containsthenull
reference. This constructor throws
IllegalArgumentException
when
initialCapacity
is less than 1.
•
PriorityQueue(PriorityQueue<? extends E> pq)
creates a
PriorityQueue
instancecontaining
pq
'selements.Thispriorityqueuewill
be ordered according to the same ordering as
pq
. This constructor throws
ClassCastException
when
pq
'selementscannotbecomparedtoonean-
other according to
pq
's ordering, and
NullPointerException
when
pq
or any of its elements contains the null reference.
•
PriorityQueue(SortedSet<? extends E> ss)
creates a
Pri-
orityQueue
instance containing
ss
's elements. This priority queue will
be ordered according to the same ordering as
ss
. This constructor throws
ClassCastException
when
sortedSet
'selementscannotbecompared
to one another according to
ss
's ordering, and
NullPointerException
when
sortedSet
or any of its elements contains the null reference.
Listing 5-14
demonstrates a priority queue.
Listing 5-14.
Adding randomly generated integers to a priority queue