package devmanuals.com; import java.util.Queue; import java.util.LinkedList; import java.util.Iterator; public class QueuePoll { 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 before removing element : " + q.size()); System.out .println("Now after removing the head of the queue new queue is "); Object obj = q.poll(); System.out.println(q); System.out.println("Removed element = " + obj); System.out .println("Size of queue after removing element : " + q.size()); System.out.println("Removes all the elements from queue"); Iterator lq = q.iterator(); while (lq.hasNext()) { q.poll(); } System.out.println(q); System.out.println("Is queue empty : " + q.isEmpty()); // Here implementation of the poll( ) method will display 'null' System.out.println(q.poll()); } }