Java Program to Get the Size of the Queue Collection

You are currently viewing Java Program to Get the Size of the Queue Collection

Java program to get the size of the Queue collection

// Java program to get the size of 
// the Queue collection

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Queue < Integer > queue = new LinkedList < > ();

    queue.add(10);
    queue.add(20);
    queue.add(30);
    queue.add(40);
    queue.add(50);

    Iterator itr = queue.iterator();
    System.out.println("Queue elements: ");
    while (itr.hasNext()) {
      System.out.print(itr.next() + " ");
    }
    System.out.println("\nSize of Queue is: " + queue.size());
  }
}

Output

Queue elements: 
10 20 30 40 50 
Size of Queue is: 5

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply