title: What is the preferred way to compare two Java Strings lexicographically on *Unicode code points*?
body: <p>For a Java program I'm writing, I have a particular need to sort strings lexicographically by Unicode code point. This is <em>not</em> the same as <code>String.compareTo()</code> when you start dealing with values outside the Basic Multilingual Plane. <code>String.compareTo()</code> compares strings lexicographically on 16-bit <code>char</code> values. To see that this is not equivalent, note that U+FD00 ARABIC LIGATURE HAH WITH YEH ISOLATED FORM is less than U+1D11E MUSICAL SYMBOL G CLEF, but the Java <code>String</code> object <code>"\uFD00"</code> for the Arabic character compares greater than the surrogate pair <code>"\uD834\uDD1E"</code> for the clef.</p>
  
  <p>I can manually loop along the code points <a href="https://stackoverflow.com/a/1527891/925960">using <code>String.codePointAt()</code> and <code>Character.charCount()</code></a> and do the comparison myself if necessary. Is there an API function or other more "canonical" way of doing this?</p>