title: Sorting Priority Queue in Java
body: <p>I was trying to insert the integers in <code>PriorityQueue</code>, and I know that :</p>
  
  <p><strong>If no comparator is specified when a <code>PriorityQueue</code> is constructed, then the default
  comparator for the type of data stored in the queue is used. The default comparator will order
  the queue in ascending order</strong></p>
  
  <p>However, the output I am getting is not in sorted order.
  Output after running the below code is : <code>[2, 4, 8, 6]</code></p>
  
  <pre><code>public static void main(String args[]) {
      PriorityQueue&lt;Integer&gt; q = new PriorityQueue&lt;Integer&gt;(10);
      q.offer(4);
      q.offer(2);
      q.offer(8);
      q.offer(6);
  
      System.out.print(q);
  }
  </code></pre>
  
  <p>Can someone please explain why ?</p>