public class PriorityQueue<E>
extends java.util.PriorityQueue<E>
PriorityQueuewould producepq = new PriorityQueue (); pq.add("foobar"); pq.add("tra"); pq.add("priorityqueue"); pq.add("et cetera"); String polled; while ((polled = pq.poll()) != null) System.out.println(polled);
et cetera foobar priorityqueue traWith Strings it is worth noting that the sorting is case sensitive so that Strings starting with capital letters take precedence.
PriorityQueue
,
Serialized FormConstructor and Description |
---|
PriorityQueue()
Creates a PriorityQueue with the default initial capacity
(11) that orders its elements according to their natural
ordering (using
java.util.Comparable ). |
PriorityQueue(java.util.Collection<? extends E> c)
Creates a PriorityQueue containing the elements in the
specified collection.
|
PriorityQueue(int initialCapacity)
Creates a PriorityQueue with the specified initial capacity
that orders its elements according to their natural ordering
(using
java.util.Comparable ). |
PriorityQueue(int initialCapacity,
java.util.Comparator<? super E> comparator)
Creates a PriorityQueue with the specified initial capacity
that orders its elements according to the specified comparator.
|
PriorityQueue(PriorityQueue<? extends E> c)
Creates a PriorityQueue containing the elements in the
specified collection.
|
PriorityQueue(java.util.SortedSet<? extends E> c)
Creates a PriorityQueue containing the elements in the
specified collection.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o) |
void |
clear() |
java.util.Comparator<? super E> |
comparator() |
java.util.Iterator<E> |
iterator() |
E |
poll() |
boolean |
remove(java.lang.Object o) |
int |
size() |
contains, offer, peek, spliterator, toArray, toArray
containsAll, isEmpty, removeAll, retainAll, toString
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
public PriorityQueue()
java.util.Comparable
).public PriorityQueue(int initialCapacity)
java.util.Comparable
).initialCapacity
- the initial capacity for this priority queue.java.lang.IllegalArgumentException
- if initialCapacity is less
than 1public PriorityQueue(int initialCapacity, java.util.Comparator<? super E> comparator)
initialCapacity
- the initial capacity for this priority queue.comparator
- the comparator used to order this priority queue.
If null then the order depends on the elements' natural
ordering.java.lang.IllegalArgumentException
- if initialCapacity is less
than 1public PriorityQueue(java.util.Collection<? extends E> c)
c
- the collection whose elements are to be placed
into this priority queue.java.lang.ClassCastException
- if elements of the specified collection
cannot be compared to one another according to the priority
queue's ordering.java.lang.NullPointerException
- if c or any element within it
is nullpublic PriorityQueue(PriorityQueue<? extends E> c)
c
- the collection whose elements are to be placed
into this priority queue.java.lang.ClassCastException
- if elements of the specified collection
cannot be compared to one another according to the priority
queue's ordering.java.lang.NullPointerException
- if c or any element within it
is nullpublic PriorityQueue(java.util.SortedSet<? extends E> c)
c
- the collection whose elements are to be placed
into this priority queue.java.lang.ClassCastException
- if elements of the specified collection
cannot be compared to one another according to the priority
queue's ordering.java.lang.NullPointerException
- if c or any element within it
is null