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?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.