Java中PriorityQueue(优先队列)使用范例代码
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()); } }