In Java, how does Unicode strings get compared?
What I mean is, if I have a few say, Japanese strings, when I do the following:
java.util.Arrays.sort(arrayOfJapaneseStrings);
how does those strings get compared and sorted?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
By default, Strings sort lexicographically, by Unicode order. The order is by UTF-16, so might not be exactly what you want for certain characters, but Japanese characters are all in the BMP, so you shouldn’t have a problem with these.
If you would like a different sort order, you can use the
java.text.Collatorclasses to define a different sort order.