package devmanuals.com; import java.util.Deque; import java.util.LinkedList; import java.util.Iterator; public class DequeRemoveFirst { public static void main(String[] args) { Deque dq = new LinkedList(); dq.add(10); dq.add(11); dq.add("Java"); dq.add("Dev"); dq.add("Manuals"); dq.add(".Com"); System.out.println("Is deque empty : " + dq.isEmpty()); System.out.println("Elements of deque : " + dq); System.out.println("Size of deque before removing an element : " + dq.size()); System.out .println("Now after removing the first element from deque new deque is "); Object obj = dq.removeFirst(); System.out.println(dq); System.out.println("Removed element is = " + obj); System.out.println("Size of deque after removing element : " + dq.size()); //Removes all the elements from deque Iterator it = dq.iterator(); while (it.hasNext()) { dq.remove(); } System.out.println("After removing all the elements "); System.out.println("from deque then deque = "+dq); System.out.println("Is deque empty : " + dq.isEmpty()); // Here implementation of the removeFirst( ) method will display an exception System.out.println(dq.removeFirst()); } }