Lecture Videos
  1  import java.util.*;
  2  
  3  public class PriorityQueueDemo {
  4    public static void main(String[] args) {
  5      PriorityQueue<String> queue1 = new PriorityQueue<>();
  6      queue1.offer("Oklahoma");
  7      queue1.offer("Indiana");
  8      queue1.offer("Georgia");
  9      queue1.offer("Texas");
 10  
 11      System.out.println("Priority queue using Comparable:");
 12      while (queue1.size() > 0) {
 13        System.out.print(queue1.remove() + " ");
 14      }
 15  
 16      PriorityQueue<String> queue2 = new PriorityQueue<>(
 17        4, Collections.reverseOrder());
 18      queue2.offer("Oklahoma");
 19      queue2.offer("Indiana");
 20      queue2.offer("Georgia");
 21      queue2.offer("Texas");
 22  
 23      System.out.println("\nPriority queue using Comparator:");
 24      while (queue2.size() > 0) {
 25        System.out.print(queue2.remove() + " ");
 26      }
 27    }
 28  }