Share on Google+Share on Google+

Java Queue

A queue is a collection interface that holds the objects.

Java Queue


A queue is a collection interface that holds the objects. collections are designed to hold elements prior to processing. Queues provide additional insertion, extraction, and inspection operations along with the collection operations.

Mostly but not necessarily queues, order elements in a FIFO (first-in-first-out) manner. It is independent of the order used, while the head of the queue is that element which would be removed by a call to remove() or poll(). In case of FIFO queue, elements are inserted from the tail of the queue. While different queues may use different placement rules. Every Queue implementation must specify its ordering properties.

The offer() method inserts an element if possible, otherwise returning false that is designed for normal failures rather than exceptional occurrences such as fixed capacity (or bounded) queue. Methods remove() and poll() are used to remove the element that returns the head of the queue. Methods remove() and poll() are different only in that remove() method throws an exception whenever the queue is empty, while the method poll() returns null.

Methods element() and peek() returns rather than removing the head of the queue.

To know more about java queue go to the link:  





Posted on: December 18, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Java Queue  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image