package devmanuals.com; import java.util.Deque; import java.util.Iterator; import java.util.LinkedList; public class DequeGetFirst { public static void main(String args[]) { Deque dq = new LinkedList(); dq.add(1); dq.add(2); dq.add(3); dq.add(4); System.out.println("Is Deque empty : " + dq.isEmpty()); System.out.println("Elements of Deque = " + dq); System.out.println("Size of Deque : " + dq.size()); Object obj=dq.getFirst(); System.out.println("Element at the first position is : "+obj); Iterator it =dq.iterator(); while(it.hasNext()){ dq.remove(); } System.out.println("Is Deque empty : " + dq.isEmpty()); // Here is the use of getFirst() method will display exception Object obj1=dq.getFirst(); System.out.println(obj1); } }