According to the javadoc for the iterator:
The iterator does not return the elements in any particular order.
However, the first item (head) is guaranteed to be the smallest. So this should print what you expect:
public static void main(String[] args) throws Exception {
Queue<String> q = new PriorityQueue<String>();
q.offer("car");
q.offer("airplane");
q.offer("bicycle");
String e = null;
while ((e = q.poll()) != null) {
System.out.println(e);
}
}
If you want iteration to be sorted, you need to use a different structure, for example a TreeSet
if you don't have duplicates.