PriorityQueue class toArray()method example

Returns an array containing all of the elements in this queue.


PriorityQueue class toArray()method example. This example shows you how to use toArray()method.This method Returns an array containing all of the elements in this queue.

Here is the code:-
/**
 * @Program that Returns an array containing all of the elements in this queue.
 * ToArray.java 
 * Author:-RoseIndia Team
 * Date:-28-May-2008
 */
import java.util.*;
public class ToArray {
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");
//Returns an array containing all of the elements in this queue.
Object o[]=p.toArray();
System.out.println("Elements of the array are: ");
//For displaying the elements of the Array
for(int i=0;i<o.length;i++)
System.out.print(o[i]+"\t");
}
}

Output of the program:-
Elements of the array are:
1    2    3    4    5    6

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

HOME | COPYRIGHT | CONTACT US