import java.util.LinkedList; import java.util.Queue; public class UsingJAVA { public static void main(String[] args) { Queue myQueue = new LinkedList(); myQueue.add("I"); myQueue.add("am"); myQueue.add("Learning"); myQueue.add("JAVA."); myQueue.add("It"); myQueue.add("is"); myQueue.add("Interesting."); System.out.println("The size of the queue is :"); System.out.print(myQueue.size()); System.out.println(); String a; String b; System.out.println("The result after peek and element is:"); a=myQueue.peek(); //peek retrieves but does not remove b=myQueue.element(); //remove and element throw exceptions System.out.print(a); System.out.println(); System.out.print(b); System.out.println(); System.out.println("Using 'poll', which removes the items"); System.out.print(myQueue.poll()); //poll removes System.out.println(); System.out.print(myQueue.poll()); System.out.println(); System.out.println("'Remove' command removes an element which is:"); System.out.println(myQueue.remove()); System.out.println("Emptying the whole queue using clear command"); myQueue.clear(); System.out.println(); System.out.println("Size of the queue after clearance is:"); System.out.print(myQueue.size()); } }