Using a queue implemented through the Queue interface is very similar to using a stack. Here is a sample program that uses some of the key operations provided by a Queue implementation.
Program 39-1
public static void main(String[] args)
{
ListQueue queue;
for (int k = 1; k <= 5; k++)
queue.enqueue(new Integer(k));
while (!queue.isEmpty())
{
System.out.println(queue.dequeue());
}
}
Run output:
1 2 3 4 5