Reputation: 11
How can I sort Strings with String.CASE_INSENSITIVE_ORDER, using collator or comparator? Actually, how can i combine them?
Comparator comparator=(Collator.getInstance(Locale.forLanguageTag(inputs.getLocale())));
Collections.sort(lines,String.CASE_INSENSITIVE_ORDER);
Upvotes: -1
Views: 151
Reputation: 2605
String.CASE_INSENSITIVE_ORDER is itself a static Comparator.
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#CASE_INSENSITIVE_ORDER
You can chain multiple comparators by using thenComparing eg.
Comparator<String> cmp = Comparator.comparingInt(String::length)
.thenComparing(String.CASE_INSENSITIVE_ORDER);
Upvotes: 0