process(list.get(i));
will typically be faster than using
Iterator it = list.iterator();
while (it.hasNext())
process(it.next());
then your list should implement RandomAccess.
21.7. Queue
The Queue
collection. A queue defines a head position, which is the next element that would be removed. Queues often
operate on a first-in-first-out ordering, but it is also possible to have last-in-first-out ordering (commonly
known as a stack) or to have a specific ordering defined by a comparator or by comparable elements. Each
implementation must specify its ordering properties. The Queue interface adds several methods that work
specifically with the head:
public Eelement()
Returns, but does not remove, the head of the queue. If the queue is empty a
NoSuchElementException is thrown.
public Epeek()
Returns, but does not remove, the head of the queue. If the queue is empty,
null is returned. This differs from element only in its handling of an
empty queue.
public Eremove()
Returns and removes the head of the queue. If the queue is empty a
NoSuchElementException is thrown.
public Epoll()
Returns and removes the head of the queue. If the queue is empty, null is
returned. This differs from remove only in its handling of an empty queue.
There is also a method for inserting into a queue:
public booleanoffer(E elem)
Attempts to insert the given element into this queue. If the attempt is
successful, true is returned, otherwise false. For queues that have
genuine reason to reject a requestsuch as a queue with finite capacitythis
method is preferable to the Collectionadd method which can only
indicate failure by throwing an exception.