PriorityQueue in Java

import java.util.PriorityQueue;
 
public class Cars {
   public static void main(String[] args) {
      PriorityQueue<String> car = new PriorityQueue<String>();
      car.add("lincoln");
      car.add("ford");
      car.add("suzuki");
      car.add("toyota");
      car.add("nissan");
      System.out.println("The car: ");
      for (String name : car) {
         System.out.println(name);
      }
      car.poll();
      System.out.println("The car: ");
      for (String name : car) {
         System.out.println(name);
      }
      car.remove("suzuki");
      System.out.println("The car: ");
      for (String name : car) {
         System.out.println(name);
      }
      System.out.println("The head: " + car.peek());
   }
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.