title: Understanding Comparator call to compare method
body: <p>I am going through the following code from <a href="http://www.programcreek.com/2011/12/examples-to-demonstrate-comparable-vs-comparator-in-java/" rel="nofollow">here</a>:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Comparator;
  
  class HDTV {
      private int size;
      private String brand;
  
      public HDTV(int size, String brand) {
          this.size = size;
          this.brand = brand;
      }
  
      public int getSize() {
          return size;
      }
  
      public void setSize(int size) {
          this.size = size;
      }
  
      public String getBrand() {
          return brand;
      }
  
      public void setBrand(String brand) {
          this.brand = brand;
      }
  }
  
  class SizeComparator implements Comparator&lt;HDTV&gt; {
      @Override
      public int compare(HDTV tv1, HDTV tv2) {
          int tv1Size = tv1.getSize();
          int tv2Size = tv2.getSize();
  
          if (tv1Size &gt; tv2Size) {
              return 1;
          } else if (tv1Size &lt; tv2Size) {
              return -1;
          } else {
              return 0;
          }
      }
  }
  
  public class Main {
      public static void main(String[] args) {
          HDTV tv1 = new HDTV(55, "Samsung");
          HDTV tv2 = new HDTV(60, "Sony");
          HDTV tv3 = new HDTV(42, "Panasonic");
  
          ArrayList&lt;HDTV&gt; al = new ArrayList&lt;HDTV&gt;();
          al.add(tv1);
          al.add(tv2);
          al.add(tv3);
  
          Collections.sort(al, new SizeComparator());
          for (HDTV a : al) {
              System.out.println(a.getBrand());
          }
      }
  }
  </code></pre>
  
  <p>When <code>new SizeComparator()</code> method is called inside <code>Collections.sort()</code>, as far as I have understood size of <code>tv1</code> is first compared to <code>tv2</code>. And here since <code>tv1</code> size is less than <code>tv2</code>,the <code>compare</code> method will return <code>-1</code>. In the next step, how will the size of <code>tv3</code> would be compared?
  Is it like <code>-1</code> is compared to <code>42</code> ? </p>