I've just spent almost hour debugging a List<String>
in my code which was being sorted wrong by my Comparator
.
Turns out that string.compareTo(string2)
is case-sensitive. Meaning that all Capital letters come before the lowercase letters. e.g. "Z" comes before "d".
Is there any better way of comparing 2 Strings
inside a Comparator
and sorting them alphabetically ascending without them being case sensitive other then string.toLowerCase().compareTo(string2.toLowerCase());
?
Edit: There's a possibility of any accented letter appearing in my String
like for example: ä, ö, ü, é, è, etc.