package devmanuals.com; import java.util.Queue; import java.util.LinkedList; import java.util.Iterator; public class QueueRemove { 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.remove(); 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.remove(); System.out.println(q); System.out.println("Is queue empty : "+q.isEmpty()); //Here implementation of the remove( ) method will throw an exception q.remove(); } }