Queue

A Queue is a collection that usually stores elements for later use. You can put elements into a queue and you can pull them out. An implementation may specify the given order, that may be first in first out (FIFO) or last in first out (LIFO), or some priority-based ordering.

On a queue, you can invoke the add() method to add an element, remove() to remove the head element, and the element() method to access the head element without removing it from the queue. The add() method will throw an exception when there is a capacity problem and the element cannot be added to the queue. When the queue is empty, and there is no head element, the element() and remove() methods throw exceptions.

As exceptions can only be used in exceptional cases, ...

Get Java Projects - Second 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.