Name

PriorityQueue<E>

Synopsis

This class is a Queue implementation that orders its elements according to a specified Comparator or orders Comparable elements according to their compareTo( ) methods. The head of the queue (the element removed by remove( ) and poll( )) is the smallest element on the queue according to this ordering. The Iterator return by the iterator( ) method is not guaranteed to iterate the elements in their sorted order.

PriorityQueue is unbounded and prohibits null elements. It is not threadsafe.

java.util.PriorityQueue<E>

Figure 16-47. java.util.PriorityQueue<E>

public class PriorityQueue<E> extends AbstractQueue<E> implements Serializable {
// Public Constructors
     public PriorityQueue( );  
     public PriorityQueue(int initialCapacity);  
     public PriorityQueue(SortedSet<? extends E> c);  
     public PriorityQueue(PriorityQueue<? extends E> c);  
     public PriorityQueue(Collection<? extends E> c);  
     public PriorityQueue(int initialCapacity, Comparator<? super E> comparator);  
// Public Instance Methods
     public Comparator<? super E> comparator( );  
// Methods Implementing Collection
     public Iterator<E> iterator( );  
     public boolean remove(Object o);  
     public int size( );  
// Methods Implementing Queue
     public boolean offer(E o);  
     public E peek( );  
     public E poll( );  
// Public Methods Overriding AbstractQueue
     public boolean add(E o);  
     public void clear( );  
}

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.