Consider the following program and predict the output:
import java.util.*; public class Main { public static void main(String []args) { Deque<Integer> deque = new LinkedList<>(); deque.add(10);/*from w ww. j av a 2 s .com*/ deque.add(20); deque.peek(); deque.peek(); deque.peek(); //#1 System.out.println(deque); } }
a)
The method peek()
retrieves an element from the head of the Deque and returns, but does not remove the element.
Hence, there will be no impact on the Deque.