Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Name

Queue<E>

Synopsis

A Queue<E> is an ordered Collection of elements of type E. Unlike List, the Queue interface does not permit indexed access to its elements: elements may be inserted at the tail of the queue and may be removed from the head of the queue, but the elements in between may not be accessed by their position. Unlike Set, Queue implementations do not prohibit duplicate elements.

Queues may be manipulated through the methods of the Collection interface, including iteration via the iterator( ) method and the Iterator object it returns. It is more common to manipulate queues through the more specialized methods defined by the Queue interface, however. Place an element at the tail of the queue with offer( ). If the queue is already full, offer( ) returns false. Remove an element from the head of the queue with remove( ) or poll( ). These methods differ only in the case of an empty queue: remove( ) throws an unchecked NoSuchElementException and poll( ) returns null. (Most queue implementations prohibit null elements for this reason, but LinkedList is an exception.) Query the element at the head of a queue without removing it with element( ) or peek( ). If the queue is empty, element( ) throws NoSuchElementException and peek( ) returns null.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint