I want to order the list in ascending order, but it is arranged in upper case and then lower case. Is it possible to arrange the list as expected output given below? If yes, could you provide the solution and how it can be achieved?
List<String> list=new ArrayList<String>();
list.add("Famous");
list.add("1996");
list.add("famous");
list.add("Popular");
list.add("2023");
list.add("popular");
Collections.sort(list);
Actual Output:
1996,2023,Famous,Popular,famous,popular
Excepted Output:
1996,2023,famous,Famous,popular,Popular
>Solution :
You can do this using the built-in comparator String.CASE_INSENSITIVE_ORDER:
Collections.sort(list, String.CASE_INSENSITIVE_ORDER)