I've been reading about using Collator and the compareTo method in String for comparing Strings. I'm unsure what the real difference is between the two from reading the API. When is one to prefer over the other?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Basically, locale-sensitive means that it takes into account the language being used and may use different weights for comparisons between different characters.
With the lexicographical comparison of compareTo it just uses their Unicode values instead of taking these different weights into account.
1 Colator Javadoc
Promoted from my comment (which sort of half answers the question):
Use a collator: Suppose you have a contact manager for a company that has international locations. Suppose you have an autocomplete with prefix matching. The collator can allow your US employees to find a match on accented vowels in names without typing in the accents.
Use compareTo: when you don't care about situations like I just gave.