title: compareTo() vs. equals()
body: <p>When testing for equality of <code>String</code>'s in Java I have always used <code>equals()</code> because to me this seems to be the most natural method for it. After all, its name already says what it is intended to do. However, a colleague of mine recently told me had been taught to use <code>compareTo() == 0</code> instead of <code>equals()</code>. This feels unnatural (as <code>compareTo()</code> is meant to provide an ordering and not compare for equality) and even somewhat dangerous (because <code>compareTo() == 0</code> does not necessarily imply equality in all cases, even though I know it does for <code>String</code>'s) to me.</p>
  
  <p>He did not know why he was taught to use <code>compareTo()</code> instead of <code>equals()</code> for <code>String</code>'s, and I could also not find any reason why. Is this really a matter of personal taste, or is there any real reason for either method?</p>