Given:
Deque <String> myDeque = new ArrayDeque<String>();
myDeque.push(“one”);
myDeque.push(“two”);
myDeque.push(“three”);
System.out.println(myDeque.pop());
What is the result?
A.
Three
B.
One
C.
Compilation fails.
D.
The program runs, but prints no output.
push() is to add to the first, pop() is to pop from the first.
A three
push() and pop() work as Stack methods. So do not get confused with as a Queue.
tail—————head (add() adds to tail and remove() from head )
tail—————head ( push() to head and pop() from head() )
try this:
myDeque.push(“one”);
myDeque.push(“two”);
myDeque.push(“three”);
myDeque.add( “five” );
System.out.println( myDeque );