Take the 2-minute tour ×

Why does java.util.Stack allows me to create a new Stack in an android activity with a simple constructor like:

Stack < ImageView> stack = new Stack< ImageView>();

and i cannot do the same with java.util.Queue? Shouldn't a queue have a similar constructor? Strange enough on http://developer.android.com/reference/java/util/Stack.html it says the Stack has a public constructor and on http://developer.android.com/reference/java/util/Queue.html i don't see a similar constructor for a queue.. why is that? what is the way to have a Queue of ImageView elements for example? Thanks.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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

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


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

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

        String iteratorValue=(String)it.next();
        System.out.println("Queue Next Value :"+ iteratorValue);
share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer


