write by lucas
PriorityQueue pq = new PriorityQueue();
pq.offer("A");
pq.offer("C");
pq.offer("B");
pq.offer("X");
while (pq.size() > 0) {
System.out.print( pq.poll() + " ");
}
hi,
lucas
the output is a,b,c,x is correct. the PriorityQueue which is specified either according to their natural order (see Comparable), or according to a Comparator, depending on which constructor is used.see natural order in the sense not the order which is specified in your program,the alphabet order
if you use this constructor you can get the output as you expected
public PriorityQueue(int initialCapacity, Comparator<? super E> comparator)
i don't know in real time where this concepts are used.
hope you understand.