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
add() adds to the first while remove() removes the last.
Sorry I was wrong. add() adds to the tail while remove() removes from the head.
B one
B