title: What is the difference between compareTo and equals in Kotlin?
body: <p>I want to fully understand the different between <code>compareTo</code> and <code>equals</code>.</p>
  
  <p><strong>I have used this code while trying to understand the difference between them:</strong></p>
  
  <pre><code>println("${'A'.compareTo('b')}")
  println("${'A'.equals('b')}")
  </code></pre>
  
  <p>While using <code>compareTo</code> I get <code>-1</code> as a result. Nothing is wrong here.
  It is also <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-comparable/compare-to.html" rel="nofollow noreferrer">mentioned in the documentation</a> that I will get <code>-1</code> as a result if the strings are not the same:</p>
  
  <blockquote>
    <p>Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it's less than other, or a positive number if it's greater than other.</p>
  </blockquote>
  
  <p>And while using <code>equals</code> the result that I got was <code>false</code>, then again it looks good as <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/equals.html" rel="nofollow noreferrer">the documentation mentioned</a> - this method will return a boolean:</p>
  
  <blockquote>
    <p>Indicates whether some other object is "equal to" this one. </p>
  </blockquote>
  
  <p>Maybe I am missing something really simple, but in the described case, what is the difference between those methods (other than the value that is coming from <code>compareTo</code> and <code>equals</code>)? </p>