title: PriorityQueue containing "Pairs" in reverse numerical order Java
body: <p>I'm trying to create a priorityqueue which keeps its elements(Pairs of integers) in the reverse of the natural order. I've found severeal tips on the site, but in every case it gave the same wrong order.</p>
  
  <p></p>
  
  <pre><code>    PriorityQueue&lt;Pair&gt; pq = new PriorityQueue(4,
              new Comparator&lt;Pair&gt;() {
                  public int compare(Pair a1, Pair a2) {
                      return a2.value.compareTo(a1.value);
                  }
      });
      pq.add(new Pair(1,15));
      pq.add(new Pair(2,58));
      pq.add(new Pair(3,55));
      pq.add(new Pair(7,23));
      Iterator&lt;Pair&gt; it = pq.iterator();
      while(it.hasNext()) {
          System.out.println(it.next().value);
      }
  </code></pre>
  
  <p></p>
  
  <p>Here is the Pair class</p>
  
  <p></p>
  
  <pre><code>public class Pair implements Comparable {
  public Integer name;
  public Integer value;
  public Pair(int name, int value) {
      this.name = name;
      this.value = value;
  
  }
  public int getname(){
      return name;
  }    
  public int getvalue() {
      return value;
  }
  
  public int compare(Pair o1, Pair o2) {
      Pair a1 = (Pair)o1;
      Pair a2 = (Pair)o2;
      if(a1.value&gt;a2.value) {
          return 1;
      }
      else if(a1.value&lt;a2.value) {
          return -1;
      }
      return 0;
  
  }
  
  @Override
  public int hashCode() {
      int hash = 3;
      return hash;
  }
  @Override
  public boolean equals(Object o) {
      Pair a2 = (Pair)o;
      return this.name == a2.name &amp;&amp; this.value == a2.value;
  }
  public int compareTo(Object o) {
      Pair a2 = (Pair)o;
      if(this.value&gt;a2.value) {
          return 1;
      }
      else if(this.value&lt;a2.value) {
          return -1;
      }
      return 0;
  
  }
  </code></pre>
  
  <p>}
  </p>
  
  <p>If I use the "new PriorityQueue()" constructor, it gives a proper natural ordering.
  Thanks for your time, 
  Mark</p>