title: Why does the equals method in String not use hash?
body: <p>The code of the <code>equals</code> method in class String is</p>
  
  <pre><code>public boolean equals(Object anObject) {
      if (this == anObject) {
          return true;
      }
      if (anObject instanceof String) {
          String anotherString = (String)anObject;
          int n = count;
          if (n == anotherString.count) {
              char v1[] = value;
              char v2[] = anotherString.value;
              int i = offset;
              int j = anotherString.offset;
              while (n-- != 0) {
                  if (v1[i++] != v2[j++])
                      return false;
              }
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>I have a question - why does this method not use hashCode() ? </p>
  
  <p>As far as I know, hashCode() can compare two strings rapidly.</p>
  
  <p>UPDATE: I know, that two unequal strings, can have same hashes. But two equal strings have equal hashes. So, by using hashCode(), we can immediately see that two strings are unequal.</p>
  
  <p>I'm simply thinking that using hashCode() can be a good <strong>filter</strong> in <code>equals</code>.</p>
  
  <p>UPDATE 2: Here some code, about we are talking here.</p>
  
  <p>It is an example how String method equals can look like</p>
  
  <pre><code>public boolean equals(Object anObject) {
      if (this == anObject) {
          return true;
      }
      if (anObject instanceof String) {
          String anotherString = (String)anObject;
          if (hashCode() == anotherString.hashCode()){
              int n = count;
              if (n == anotherString.count) {
                  char v1[] = value;
                  char v2[] = anotherString.value;
                  int i = offset;
                  int j = anotherString.offset;
                  while (n-- != 0) {
                      if (v1[i++] != v2[j++])
                          return false;
                  }
                  return true;
              }
          }else{
              return false;
          }
      }
      return false;
  }
  </code></pre>