Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sort the list in ascending order

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading