Android Queue vs Stack

Because Queue is an interface, you should initial it with a LinkedList:

Queue<String> qe = new LinkedList<String>();

qe.add("b");
qe.add("a");
qe.add("c");

//Traverse queue
Iterator it = qe.iterator();

System.out.println("Initial Size of Queue :" + qe.size());

while(it.hasNext())
{
   String iteratorValue = (String) it.next();
   System.out.println("Queue Next Value :" + iteratorValue);
}

It is because Queue is just an interface. To create a Queue object you need a class, what implements the methods of a Queue.

Some actual implementations of a Queue: link

Tags:

Java

Android