java.util.PriorityQueue.iterator() 方法


java.util.PriorityQueue.iterator() 方法

package com.codingdict;

import java.util.*;

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

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

      // insert values in the queue
      for ( int i = 0; i  <  10; i++ ) {  
         prq.add (new Integer (i)) ;
      }

      // create iterator from the queue
      Iterator it = prq.iterator();

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

      while (it.hasNext()) {
         System.out.println("Value: "+ it.next());
      }
   }
}