title: Java PriorityQueue with custom Comparator
body: <p>I am using a PriorityQueue and my own Comparator but somehow the end results are not always good.
  I should sort by grade average, than name, than id.no. At the end it should return the names left in the queue ordered. The remaining names are fine but their order is not.
  Input (name, grade avg, id.no):</p>
  
  <pre><code>add John 3,75 50
  add Mark 3,8 24
  add Shafaet 3,7 35
  poll
  poll
  add Samiha 3,85 36
  poll
  add Ashley 3,9 42
  add Maria 3,6 46
  add Anik 3,95 49
  add Dan 3,95 50
  poll
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>Dan
  Ashley
  Shafaet
  Maria
  </code></pre>
  
  <p>My result:</p>
  
  <pre><code>Dan
  Ashley
  Maria
  Shafaet
  </code></pre>
  
  <p>Could you please help me to find the problem?
  Thank you in advance!</p>
  
  <pre><code>class StComp implements Comparator&lt;Students&gt; {
          @Override
          public int compare(Students st1, Students st2) {
              if (st1.getCgpa() == st2.getCgpa()) {
                  if (st1.getName().equals(st2.getName()))
                      return st1.getId() - st2.getId();
                  else
                      return st1.getName().compareTo(st2.getName());
              }
              else
                  return (st1.getCgpa() &lt; st2.getCgpa()) ? 1 : -1;
          }
      }
  
      StComp stComp = new StComp();
      PriorityQueue&lt;Students&gt; pq = new PriorityQueue&lt;Students&gt;(2, stComp);
  </code></pre>