title: Why does String equals() return false (custom Comparator involved)?
body: <p>I built a very simple custom Comparator, that I use with a TreeSet in order to sort Strings by length in that TreeSet.</p>
  
  <p>I'm having trouble finding the reason why <code>(s1.equals(s2))</code> returns false even when the two strings s1 and s2 contain the same value.</p>
  
  <p>Eclipse "variables view" shows the letters are the same in both strings, but the "id" is different, I guess that's why equals returns False.
  By the way what is that <code>id=" "</code> representing? Is it some kind of pointer to the String object data?</p>
  
  <pre><code>public class MyComparator implements Comparator&lt;String&gt; {
      public int compare(String s1, String s2) {
  
          if(s1.length()&lt;s2.length()) return -1;      
          else if (s1.length()&gt;s2.length()) return 1; 
           return 0; 
          else if (s1.equals(s2)) return 0; //?? ALWAYS RETURNS FALSE
          else if (s1.toString().equals(s2.toString()))//SAME PROBLEM HERE (test)
          else return -1;
      }
  
      public boolean equals(String s) {
          if (this.equals(s)) return true;
          else return false;
      }
  }
  </code></pre>
  
  <p>Now here is where I use this custom Comparator:</p>
  
  <pre><code>combinations = new TreeSet&lt;String&gt;(new MyComparator());
  </code></pre>
  
  <p>I fill combinations with several Strings, built with the <code>substring()</code> method.</p>
  
  <p>Because of the previously mentioned problem, combinations contains duplicates.</p>
  
  <p>When I set NO custom Comparator for this TreeSet, there is no duplicate any more (that's what I want) but it is sorted alphabetically which is normal but not my purpose.</p>