java.util
Class PriorityQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.PriorityQueue<E>
- All Implemented Interfaces:
- Serializable, Iterable<E>, Collection<E>, java.util.Queue<E>
public class PriorityQueue<E>
- extends java.util.AbstractQueue<E>
- implements Serializable
- Since:
- 1.5
- See Also:
- Serialized Form
Method Summary |
boolean |
addAll(Collection<? extends E> c)
Add all the elements of a given collection to this collection (optional
operation). |
void |
clear()
Remove all elements from the collection (optional operation). |
Comparator<? super E> |
comparator()
|
Iterator<E> |
iterator()
Return an Iterator over this collection. |
boolean |
offer(E o)
|
E |
peek()
|
E |
poll()
|
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. |
Methods inherited from class java.util.AbstractQueue |
add, element, remove |
PriorityQueue
public PriorityQueue()
PriorityQueue
public PriorityQueue(Collection<? extends E> c)
PriorityQueue
public PriorityQueue(int cap)
PriorityQueue
public PriorityQueue(int cap,
Comparator<? super E> comp)
PriorityQueue
public PriorityQueue(PriorityQueue<? extends E> c)
PriorityQueue
public PriorityQueue(SortedSet<? extends E> c)
clear
public void clear()
- Description copied from class:
AbstractCollection
- Remove all elements from the collection (optional operation). This
implementation obtains an iterator over the collection and calls next
and remove on it repeatedly (thus this method will fail with an
UnsupportedOperationException if the Iterator's remove method does)
until there are no more elements to remove.
Many implementations will have a faster way of doing this.
- Specified by:
clear
in interface Collection<E>
- Overrides:
clear
in class java.util.AbstractQueue<E>
- See Also:
Iterator.remove()
comparator
public Comparator<? super E> comparator()
iterator
public Iterator<E> iterator()
- Description copied from class:
AbstractCollection
- Return an Iterator over this collection. The iterator must provide the
hasNext and next methods and should in addition provide remove if the
collection is modifiable.
- Specified by:
iterator
in interface Iterable<E>
- Specified by:
iterator
in interface Collection<E>
- Specified by:
iterator
in class AbstractCollection<E>
- Returns:
- an iterator
offer
public boolean offer(E o)
- Specified by:
offer
in interface java.util.Queue<E>
peek
public E peek()
- Specified by:
peek
in interface java.util.Queue<E>
poll
public E poll()
- Specified by:
poll
in interface java.util.Queue<E>
remove
public boolean remove(Object o)
- Description copied from class:
AbstractCollection
- Remove a single instance of an object from this collection (optional
operation). That is, remove one element e such that
(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.
- Specified by:
remove
in interface Collection<E>
- Overrides:
remove
in class AbstractCollection<E>
- Parameters:
o
- the object to remove from this collection
- Returns:
- true if the remove operation caused the Collection to change, or
equivalently if the collection did contain o.
- See Also:
Iterator.remove()
size
public int size()
- Description copied from class:
AbstractCollection
- Return the number of elements in this collection. If there are more than
Integer.MAX_VALUE elements, return Integer.MAX_VALUE.
- Specified by:
size
in interface Collection<E>
- Specified by:
size
in class AbstractCollection<E>
- Returns:
- the size
addAll
public boolean addAll(Collection<? extends E> c)
- Description copied from class:
AbstractCollection
- Add all the elements of a given collection to this collection (optional
operation). This implementation obtains an Iterator over the given
collection and iterates over it, adding each element with the
add(Object) method (thus this method will fail with an
UnsupportedOperationException if the add method does). The behavior is
unspecified if the specified collection is modified during the iteration,
including the special case of trying addAll(this) on a non-empty
collection.
- Specified by:
addAll
in interface Collection<E>
- Overrides:
addAll
in class java.util.AbstractQueue<E>
- Parameters:
c
- the collection to add the elements of to this collection
- Returns:
- true if the add operation caused the Collection to change
- See Also:
AbstractCollection.add(Object)