Example of toArry[] method of PriorityQueue class in java.

Example of toArry[] method of PriorityQueue class in java.


Posted in : Core Java Posted on : December 10, 2010 at 6:09 PM Comments : [ 0 ]

Example of toArry[] method of PriorityQueue class in java.

Example of toArry[] method of PriorityQueue class in java.

In this example, you will see the use of toArray[] method of priority queue class. It returns a array of priority queue elements.

Code:

PriorityQueueToArrayMethod.java

import java.util.Iterator;
import java.util.PriorityQueue;

public class PriorityQueueToArrayMethod {
public static void main(String[] args) {
	PriorityQueue obQueue=new PriorityQueue();
	obQueue.add(1);
	obQueue.add(2);
	obQueue.add(3);
	obQueue.add(4);
	obQueue.add(5);
	Iterator obIt=obQueue.iterator();
	System.out.println("Element of queue");
	while (obIt.hasNext()) {
		System.out.print(obIt.next());
	}
	Object[] elementOf=obQueue.toArray();
	System.out.println("\nElement of array");
	for (int i = 0; i < elementOf.length; i++) {
		System.out.print(elementOf[i]);
	}
   }
}
Output:
Element of queue
12345
Element of array
12345

Download this code.
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics