util
Class Queue
java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractList
|
+--java.util.Vector
|
+--util.Queue
- All Implemented Interfaces:
- Cloneable, Collection, List, Serializable
- public class Queue
- extends Vector
The queue implements a first-in first-out (FIFO) set of objects.
Much like java.util.Stack, it extends class Vector with enqueue and
dequeue methods. Unlike java.util.Stack, there is no search
routine. This is a very simple layer over the Vector class, which
probably explains why there is no such thing as a queue class in
java.util.*
- See Also:
Vector
, Serialized Form
Constructor Summary |
Queue()
Creates an empty queue. |
Method Summary |
Object |
dequeue()
Removes the element from the head of the queue and returns it. |
boolean |
empty()
Checks the queue for emptiness. |
void |
enqueue(Object o)
Adds an element to the tail of the queue. |
Object |
peek()
Peeks at the first element of the queue, without removing. |
void |
promoteToFront(Object o)
Promotes the element to the front of the queue. |
Methods inherited from class java.util.Vector |
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize |
Queue
public Queue()
- Creates an empty queue.
empty
public boolean empty()
- Checks the queue for emptiness.
- Returns:
- true if the queue has no elements.
enqueue
public void enqueue(Object o)
- Adds an element to the tail of the queue.
- Parameters:
o
- the object to be inserted into the queue.
dequeue
public Object dequeue()
- Removes the element from the head of the queue and returns it.
- Returns:
- The element that was taken from the head of the queue.
peek
public Object peek()
- Peeks at the first element of the queue, without removing.
- Returns:
- The element at the head of the queue.
promoteToFront
public void promoteToFront(Object o)
- Promotes the element to the front of the queue. If it exists currently
in the queue, it gets removed
- Parameters:
o
- the object to move to the front of the queue