/**
* @author lautturi.com
* Java example: java PriorityQueue
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
// create a priority queue in reverse order
PriorityQueue<Integer> prq = new PriorityQueue<>(Comparator.reverseOrder());
// insert values to the queue
prq.add(1);
prq.add(2);
prq.add(8);
prq.add(5);
prq.add(7);
//print values in the queue
while (!prq.isEmpty()) {
System.out.print(prq.poll()+" ");
}
}
}Source:www.lautturi.comoutput:
8 7 5 2 1