import java.util.LinkedList; import java.util.Queue; public class QueueExample { public static void main(String[] args) { Queuequeue = new LinkedList<>(); queue.add("Apple"); queue.add("Banana"); queue.add("Cherry"); // Get the size of the Queue int size = queue.size(); System.out.println("Size of Queue: " + size); } }
import java.util.LinkedList; import java.util.Queue; public class QueueExample { public static void main(String[] args) { Queuequeue = new LinkedList<>(); queue.add("Apple"); queue.add("Banana"); queue.add("Cherry"); // Loop through the Queue using size() method for(int i=0; i In the above example, we have used the size() method to loop through the Queue and poll out each element from the Queue until there is no element left in the Queue. Package Library: java.util