title: Implementation of compare() method in custom created Comparators
body: <pre><code>class IntegerComparator implements Comparator&lt;Integer&gt;
  {
  @Override
  public int compare(Integer o1, Integer o2) {
      if(o1 &lt; o2)
          return 1;
      else if(o1 &gt; o2)
          return -1;
      else
      return 0;
  }   
  }
  </code></pre>
  
  <p>It gives the descending order. I know it. I remember it blindly. I dont understand why the implementation has to be like this. </p>
  
  <p>I expect the results to be ascending order. Because in ascending order, the o1 should be always less than o2 if you take any two adjacent elements. But It gives the descending order which I dont expect.</p>
  
  <p>Can someone demystify the logic behind it</p>
  
  <p>Edit:</p>
  
  <ul>
  <li>When the elements are swapped. Is it when the compare returns 1 ?</li>
  </ul>