title: Order of priorityQueue in Java?
body: <p>I can't understand the order of <code>PriorityQueue</code> in Java. As i understand they are heap based and they can not provide exact iteration order as insertion order. I want to know then on what basis priorityQueue Sort themselves.
  Given code:</p>
  
  <pre><code>PriorityQueue&lt;String&gt; pq = new PriorityQueue&lt;String&gt;();
          pq.offer("hepqo");
          pq.offer("bro");
          pq.offer("wassup");
          pq.offer("okay");
          pq.offer("bingo");
          pq.offer("first");
          pq.offer("last");
          pq.offer("ssup");
          System.out.println("polled "+pq.poll());
          System.out.println(pq);
          String str[] = pq.toArray(new String[0]);
          Arrays.sort(str);
          for(String str1:str){
              System.out.println(str1);
          }
  </code></pre>
  
  <p>produces output:</p>
  
  <pre><code>polledbingo
  [bro, hepqo, first, okay, ssup, wassup, last]
  bro
  first
  hepqo
  last
  okay
  ssup
  wassup
  </code></pre>
  
  <p>Even when i convert it to Array, the order is lost.
  <br>I can not feel this is even NATURAL ORDERING by String.
  <br> Is there any way to maintain the insertion order of priority Queues?
  <br> On what basis they sorted on?</p>