package devmanuals.com; import java.util.Queue; import java.util.LinkedList; import java.util.Iterator; public class QueueElement { public static void main(String args[]) { Queue q = new LinkedList(); q.add(1); q.add(2); q.add(3); q.add(4); q.add(5); System.out.println("Is Queue empty : " + q.isEmpty()); System.out.println("Elements of queue = " + q); System.out.println("Size of Queue : " + q.size()); Object obj = q.element(); System.out.println("Element at head position = " + obj); Iterator iq = q.iterator(); while (iq.hasNext()) { q.remove(); } System.out.println("Is Queue empty : "+q.isEmpty()); // Here the implementation of element() method will display exception System.out.println(q.element()); } }