title: Iterating through PriorityQueue doesn't yield ordered results
body: <pre><code>import java.util.*;
  class Priority{  
  public static void main(String args[]){  
  
  PriorityQueue&lt;String&gt; queue=new PriorityQueue&lt;String&gt;();  
  queue.add("Amit");  
  queue.add("Vijay");  
  queue.add("Karan");  
  queue.add("Jai");  
  queue.add("Rahul");  
  
  System.out.println("head:"+queue.element());  
  System.out.println("head:"+queue.peek());  
  
  System.out.println("iterating the queue elements:");  
  Iterator itr=queue.iterator();  
  while(itr.hasNext()){  
  System.out.println(itr.next());  
  }  
  
  queue.remove();  
  queue.poll();  
  
  System.out.println("after removing two elements:");  
  Iterator itr2=queue.iterator();  
  while(itr2.hasNext()){  
  System.out.println(itr2.next());  
  }  
  
  }  
  }  
  
  Output:head:Amit
     head:Amit
     iterating the queue elements:
     Amit
     Jai
     Karan
     Vijay
     Rahul
     after removing two elements:
     Karan
     Rahul
     Vijay
  </code></pre>
  
  <p>Hi there i was trying to learn priority queue which comes under collections in java(shown above). Now i'm really confused, because of the output. I cant understand how the output came like this (which is shown above). </p>
  
  <pre><code>iterating the queue elements:
     Amit
     Jai
     Karan
     Vijay
     Rahul
  </code></pre>
  
  <p>how does vijay came before rahul? if its in alphabetical order rahul must come before vijay i guess. </p>
  
  <p>so can anyone explain whats happening inside the program and method element() what does it do?. I couldnt find that method.</p>