by, 02-19-2012 at 06:58 AM (558 Views)
Java Queue is also collection interface for holding the objects. Collections store or hold elements, before processing. Following operations are provided by Queues:
4. (All) Other Collection operations
Queues are basically first in first order implements. They don’t depend on use order. Poll() and remove() methods are used to remove the elements present at head.
From queue’s tail, all elements gets added in case of FIFO queue. During different queues implementations, these rules might be different.
• An element is inserted by offer() method.
• The poll() or remove() methods are used for removal of the element. An exception is thrown by remove() method in case queue is empty. On the other hand, exception is not thrown by the poll() method. Just nulls is returned.
• The peek() and element() methods are used to return the elements. Head of queue is not removed by it.