Java PriorityQueue tutorial with example program


Class PriorityQueue

All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, Queue<E>

public class PriorityQueue<E>
extends AbstractQueue<E>
implements Serializable
{
   //
}
  
Since:
1.5
See Also:
Serialized Form

Constructor Summary
PriorityQueue()
Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering.

PriorityQueue(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.
PriorityQueue(int initialCapacity, 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 priority queue.
PriorityQueue(SortedSet<? extends E> c)
Creates a PriorityQueue containing the elements in the specified sorted set.


Method Summary
boolean add(E e)
Inserts the specified element into this priority queue.

void  clear()
Removes all of the elements from this priority queue.
Comparator<? super E> comparator()
Returns the comparator used to order the elements in this queue, or null if this queue is sorted according to the natural ordering of its elements.
 boolean contains(Object o)
Returns true if this queue contains the specified element.
 Iterator<E> iterator()
Returns an iterator over the elements in this queue.\
 boolean offer(E e)
Inserts the specified element into this priority queue.
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)
Removes a single instance of the specified element from this queue, if it is present.
int size()
Returns the number of elements in this collection.
 Object[] toArray()
Returns an array containing all of the elements in this queue.

 <T> T[] toArray(T[] a)
Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array.

Methods inherited from class java.util.AbstractQueue
public boolean addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this queue. Attempts to addAll of a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

public E element()
Retrieves, but does not remove, the head of this queue. This method differs from peek only in that it throws an exception if this queue is empty.

public E remove()
Retrieves and removes the head of this queue. This method differs from poll only in that it throws an exception if this queue is empty.


Methods inherited from class java.util.AbstractCollection
public boolean containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.

public boolean isEmpty()
Returns true if this collection contains no elements.
This implementation returns size() == 0.

public boolean removeAll(Collection<?> c)
Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.

public boolean retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.

Methods inherited from interface java.util.Collection
boolean containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


Related Post

Comments


©candidjava.com