public class PQSort implements Comparator <Integer> { /** * Inverse sort */ public int compare(Integer one, Integer two) { return two-one; } } ...... PQSort pqsort = new PQSort(); PriorityQueue <Integer> pq = new PriorityQueue <Integer>(10, pqsort); for (int i=0; i<10; i++) { pq.offer(x); //Adds an element } int size = pq.size(); for(int i=0;i<size;i++) System.out.print(pq.poll() + " " );//Removes the element