title: Sorting using comparator in Priority queue but not getting it right
body: <pre><code>PriorityQueue&lt;Player&gt; playerQueue = new PriorityQueue&lt;Player&gt;(30,
                  new Comparator&lt;Player&gt;( ) {
                      // overriding the compare method
                      public int compare(Player i, Player j) {
                          return (int)i.playerPrice() &lt; (int)j.playerPrice() ? -1 : ((int)i.playerPrice() == (int)j.playerPrice()) ? 0 : 1;
                      }
                  }
            );
  
          for(Player a:XMLParserViaSax.getListOfPlayers()){
              System.out.println(a.getName()+ "--&gt;"+a.playerPrice());
          }
  
          for(Player player:XMLParserViaSax.getListOfPlayers()){
              playerQueue.add(player);
          }
          //playerQueue.addAll(XMLParserViaSax.getListOfPlayers());
  
          System.out.println("**************************");
          for(Player j:playerQueue){
              System.out.println(j.getName()+ "--&gt;"+j.playerPrice());
          }
  </code></pre>
  
  <p>I am trying to sort the Player by playerprice,I don't have any variable as playerprice in Player class.playerPrice() is a method which will calculate price of a player.so now when I am trying to sort these Player Objects it is giving me a random order.</p>
  
  <p>Do I need to have one playerprice private member inside my player class ?
  '
  Player class is like this :</p>
  
  <pre><code>public class Player {
  
      private String name;
      private int battingStrength;
      private int bowlingStrength;
      private int fieldingStrength;
      private int keepingStrength;
      private int jerseyNumber;
  
      public int playerStrength() {
      return AuctionPlayerHelper.calculateStrength(this);
      }
  
      public boolean canKeepWickets() {
      return (keepingStrength == 10);
      }
  
      public boolean isForeignPlayer(){
      return AuctionPlayerHelper.isForeignPlayer(this.jerseyNumber);
      }
  
      public double playerPrice() {
       return AuctionPlayerHelper.calculatePrice(this);
  
      }
  
      //getters,setters
  }
  </code></pre>
  
  <p>'</p>