java.util.PriorityQueue.toArray() 方法


java.util.PriorityQueue.toArray() 方法

package com.codingdict;
import java.util.PriorityQueue;

public class PriorityQueueDemo {
   public static void main(String args[]) {

      // create priority queue
      PriorityQueue < Integer >  prq = new PriorityQueue < Integer > ();

      // insert values in the queue
      prq.add(6);  
      prq.add(9);
      prq.add(5);
      prq.add(64);
      prq.add(6);

      System.out.println("Priority queue values are: "+ prq);

      // get objects from the queue
      Object[] arr = prq.toArray();

      System.out.println("Value in array: ");

      for ( int i = 0; i<arr.length; i++ ) {  
         System.out.println("Value: " + arr[i].toString()) ;
      }
   }
}