1. override Comparator
import java.util.HashSet; import java.util.Stack; import java.util.Vector; import java.util.Queue; import java.util.PriorityQueue; import java.util.Comparator; public class test1 { public static void main(String[] args) { PriorityQueue<Integer> q1 = new PriorityQueue<Integer>(10,myComparator); Integer i1=new Integer(1); Integer i2=new Integer(2); q1.add(i1); q1.add(i2); while(!q1.isEmpty()) { System.out.println(q1.poll()); } } public static Comparator<Integer> myComparator = new Comparator<Integer>(){ @Override public int compare(Integer c1, Integer c2) { return (int) (c2.intValue() - c1.intValue()); } }; }