title: Strange Groovy / Java String comparison behavior
body: <p>Consider the following script:</p>
  
  <pre><code>def a = new HashSet()
  def str1 = "str1"
  def str2 = "str2"
  def b = "$str1-$str2"
  def c = "str1-str2"
  println "b: $b"
  println "c: $c"
  println "b.equals(c): " + (b.equals(c))
  println "b == c: " + (b == c)
  println "b.compareTo(c): " + (b.compareTo(c))
  
  a.add(b)
  println "a.contains(c): " + a.contains(c)
  </code></pre>
  
  <p>Which has the following output when run with Groovy 1.8 and JDK 1.6.0_14:</p>
  
  <pre><code>b: str1-str2                                                                                                               
  c: str1-str2
  b.equals(c): false
  b == c: true
  b.compareTo(c): 0
  a.contains(c): false
  </code></pre>
  
  <p>The two strings "b" and "c" print the same sequence of characters yet b.equals(c) is false. According to JDK 1.6 manual, the equals() function should return:</p>
  
  <blockquote>
    <p>Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.</p>
  </blockquote>
  
  <p>Why does equals() not return the value as documented and demonstrated above? Strangely, compareTo() returns 0!</p>