title: What determines ascending or descending order in Comparator / Comparable collection class?
body: <p>I understand we can sort or order the objects, stored in Collection as per our requirement(s).</p>
  
  <p>While I get deep understanding, I am not convinced by the fact that ascending and descending order of arrangement is achieved by (a - b) ->ascending or (b - a) -> descending where "a" and "b" are class members we chose to compare.</p>
  
  <p>Example: </p>
  
  <pre><code>public int compareTo(Student s) {
       return this.grade - s.grade; //ascending order 
      // return s.grade - this.grade; // descending order
  }
  </code></pre>
  
  <p>What is logic behind ordering object elements? how "(this.grade - s.grade)" if positive 1 moves "this.grade" front and puts "s.grade" next in order, why not other way around? Who validates the compare result (+1, -1, 0) and then puts in ascending order or descending order respectively, is there any documentation that describes internal working of this part?</p>
  
  <pre><code>public class Student implements Comparable &lt;Student&gt;{
      String name;
      int grade;
      public Student(String name, int grade) {
          this.name = name;
          this.grade = grade;
      }
      public int compareTo(Student s) {
           return this.grade - s.grade; //ascending order 
          // return s.grade - this.grade; // descending order
      }
      public String toString() {
          return this.name + ", " + this.grade;
      }
  }
  </code></pre>
  
  <p>Please share, thank you much!</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>I get the Java docs, my question is this:</p>
  
  <pre><code>sort these grades (13, 2)
  
  Case ascending -&gt; return this.grade - s.grade;
  
  picture in my mind: 
  compare (13, 2) , (13 - 2) &gt; 0 so move 2 to front.
  result -&gt; 2, 13
  ------
  Case descending -&gt; return s.grade - this.grade;
  
  picture in my mind: 
  compare (2, 13) , (2 - 13) &lt; 0 so move 13 to front.
  
  result -&gt; 13, 2
  </code></pre>
  
  <p>"How does this happen?" was my original question. I read the docs, still couldn't figure out.</p>