public class PriorityQueue<E> extends AbstractQueue<E>
Constructor and Description |
---|
PriorityQueue() |
PriorityQueue(Collection<? extends E> c) |
PriorityQueue(int cap) |
PriorityQueue(int cap,
Comparator<? super E> comp) |
PriorityQueue(PriorityQueue<? extends E> c) |
PriorityQueue(SortedSet<? extends E> c) |
Modifier and Type | Method and Description |
---|---|
boolean |
addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this
queue.
|
void |
clear()
Removes all of the elements from this queue.
|
Comparator<? super E> |
comparator() |
Iterator<E> |
iterator()
Return an Iterator over this collection.
|
boolean |
offer(E o)
Inserts the specified element into this queue if it is possible to do
so immediately without violating capacity restrictions.
|
E |
peek()
Retrieves, but does not remove, the head of this queue,
or returns null if this queue is empty.
|
E |
poll()
Retrieves and removes the head of this queue,
or returns null if this queue is empty.
|
boolean |
remove(Object o)
Remove a single instance of an object from this collection (optional
operation).
|
int |
size()
Return the number of elements in this collection.
|
add, element, remove
contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
public PriorityQueue()
public PriorityQueue(Collection<? extends E> c)
public PriorityQueue(int cap)
public PriorityQueue(int cap, Comparator<? super E> comp)
public PriorityQueue(PriorityQueue<? extends E> c)
public boolean addAll(Collection<? extends E> c)
AbstractQueue
This implementation iterates over the specified collection, and adds each element returned by the iterator to this queue, in turn. A runtime exception encountered while trying to add an element (including, in particular, a null element) may result in only some of the elements having been successfully added when the associated exception is thrown.
addAll
in interface Collection<E>
addAll
in class AbstractQueue<E>
c
- collection containing elements to be added to this queueAbstractQueue.add(Object)
public void clear()
AbstractQueue
This implementation repeatedly invokes poll
until it
returns null.
clear
in interface Collection<E>
clear
in class AbstractQueue<E>
Iterator.remove()
public Comparator<? super E> comparator()
public Iterator<E> iterator()
AbstractCollection
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in class AbstractCollection<E>
public boolean offer(E o)
Queue
Queue.add(E)
, which can fail to insert an element only
by throwing an exception.o
- the element to addpublic E peek()
Queue
public E poll()
Queue
public boolean remove(Object o)
AbstractCollection
(o == null ? e == null : o.equals(e))
, if such an element
exists. This implementation obtains an iterator over the collection
and iterates over it, testing each element for equality with the given
object. If it is equal, it is removed by the iterator's remove method
(thus this method will fail with an UnsupportedOperationException if
the Iterator's remove method does). After the first element has been
removed, true is returned; if the end of the collection is reached, false
is returned.remove
in interface Collection<E>
remove
in class AbstractCollection<E>
o
- the object to remove from this collectionIterator.remove()
public int size()
AbstractCollection
size
in interface Collection<E>
size
in class AbstractCollection<E>