How do I sort string values in case-insensitive order in the following?
List listofEmployees = Arrays.asList(
new Employee(1, \"aaa\", Ar
As @Tree suggested in comments, one can use the java.text.Collator for a case-insensitive and locale-sensitive String comparison. The following shows how both case and accents could be ignored for US English:
Collator collator = Collator.getInstance(Locale.US);
collator.setStrength(Collator.PRIMARY);
listOfEmployees.sort(Comparator.comparing(Employee::getName, collator.reversed()));
When collator strength is set to PRIMARY, then only PRIMARY differences are considered significant during comparison. Therefore, the following Strings are considered equivalent:
if (collator.compare("abc", "ABC") == 0) {
System.out.println("Strings are equivalent");
}