logo CodeStepByStep logo

queueMystery1

Language/Type: Java Stack collections

What is the output of the following code?

Queue<Integer> queue = new LinkedList<Integer>();
for (int i = 1; i <= 6; i++) {
    queue.add(i);
}                             // {1, 2, 3, 4, 5, 6}

for (int i = 0; i < queue.size(); i++) {
    System.out.print(queue.remove() + " ");
}
System.out.println(queue + "  size " + queue.size());
output

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.