I'm creating a Java PriorityQueue of Strings and naturally expecting the priority to follow lexicographic order. However, it doesn't seem to, can someone explain to me why this is the output [mackerel, trout, salmon] of the following code fragment:
java.util.PriorityQueue< String > q = new java.util.PriorityQueue<>();
q.offer( "salmon" );
q.offer( "trout" );
q.offer( "mackerel" );
System.out.println( q );
and not [mackerel, salmon, trout]? Thank you
Looked into the API and it said lexicographic order for Strings, but when ran the output is unexpected.