You can provide a custom Comparator
object that ranks elements in the reverse order:
PriorityQueue<Integer> pq = new PriorityQueue<Integer>(defaultSize, new Comparator<Integer>() {
public int compare(Integer lhs, Integer rhs) {
if (lhs < rhs) return +1;
if (lhs.equals(rhs)) return 0;
return -1;
}
});
Now, the priority queue will reverse all its comparisons, so you will get the maximum element rather than the minimum element.
Hope this helps!