title: Better way to create an ordered array from priorityQueue in Java
body: <p>I can of course do the following:</p>
  
  <pre><code>        PriorityQueue&lt;Integer&gt; q = new PriorityQueue&lt;Integer&gt;(100, new Comparator&lt;Integer&gt;() {
              public int compare(Integer x, Integer y) {
                  return Integer.valueOf(x).compareTo(y);
              }
          });
          ...//add some elements to q
          int[] arr = new int[q.size()];
          int i = 0;
          while (q.size() != 0) {
              arr[i++] = q.remove();
          }
  </code></pre>
  
  <p>But this approach emptied the queue which I want to keep. I know I could have sorted using that comparator (of course when it is not as trivial as above) to get this array, but I will have to create an array first, then copy elements from the queue to the array, then sort the array.</p>
  
  <p>Is there any better approach? Thanks for your help!</p>