PriorityQueue class size()method example

Returns the number of elements in this collection.


PriorityQueue class size()method example. This example shows you how to use size()method.This method Returns the number of elements in this collection.

Here is the code:-

/**
 * @Program that Returns the number of elements in this collection.
 * Size.java 
 * Author:-RoseIndia Team
 * Date:-28-May-2008
 */
import java.util.*;

public class Size {

    public static void main(String[] args) {
//Creating a  PriorityQueue   
        PriorityQueue p = new PriorityQueue();
//Adding element to the queue
        p.add("1");
        p.add("2");
        p.add("3");
        p.add("4");
        p.add("5");
        p.add("6");
//creating an iterator interface
        Iterator i = p.iterator();
        System.out.print("Elements of the Queue are: ");
        while (i.hasNext()) {
            System.out.print(i.next() "\t");
        }
        System.out.println();
//Returns the number of elements in this collection.
        System.out.println("Size of the Queue is: " + p.size());
    }
}

Output of the program:-
Elements of the Queue are: 1    2    3    4    5    6   
Size of the Queue is: 6

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US