title: Understanding logic in CaseInsensitiveComparator
body: <p>Can anyone explain the following code from <code>String.java</code>, specifically why there are three <code>if</code> statements (which I've marked <code>//1</code>, <code>//2</code> and <code>//3</code>)?</p>
  
  <pre><code>private static class CaseInsensitiveComparator
                       implements Comparator&lt;String&gt;, java.io.Serializable {
  // use serialVersionUID from JDK 1.2.2 for interoperability
  private static final long serialVersionUID = 8575799808933029326L;
  
      public int compare(String s1, String s2) {
          int n1=s1.length(), n2=s2.length();
          for (int i1=0, i2=0; i1&lt;n1 &amp;&amp; i2&lt;n2; i1++, i2++) {
              char c1 = s1.charAt(i1);
              char c2 = s2.charAt(i2);
              if (c1 != c2) {/////////////////////////1
                  c1 = Character.toUpperCase(c1);
                  c2 = Character.toUpperCase(c2);
                  if (c1 != c2) {/////////////////////////2
                      c1 = Character.toLowerCase(c1);
                      c2 = Character.toLowerCase(c2);
                      if (c1 != c2) {/////////////////////////3
                          return c1 - c2;
                      }
                  }
              }
          }
          return n1 - n2;
      }
  }
  </code></pre>