What is the result?

Given the following code fragment:

public static void main(String[] args) {

Connection conn = null;

Deque<String> myDeque = new ArrayDeque<>();

myDeque.add(“one”);

myDeque.add(“two”);

myDeque.add(“three”);

System.out.println(myDeque.remove());

}

What is the result?

Given the following code fragment:

public static void main(String[] args) {

Connection conn = null;

Deque<String> myDeque = new ArrayDeque<>();

myDeque.add(“one”);

myDeque.add(“two”);

myDeque.add(“three”);

System.out.println(myDeque.remove());

}

What is the result?

A.
Three

B.
One

C.
Compilation fails

D.
The program runs, but prints no outout

Explanation:
TheArrayDeque.remove() method retrieves and removes the head of the queue represented by this deque.The head of the queue is item “one”.

Reference:java.util

Class ArrayDeque



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Charlie

Charlie

add() adds to the first while remove() removes the last.

Charlie

Charlie

Sorry I was wrong. add() adds to the tail while remove() removes from the head.