Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ignore case when sorting list

I have a List named path I'm currently sorting my strings with the following code

  java.util.Collections.sort(path);

That is working fine it sorts my list however it treats the cases of the first letter differently that is it sorts the list with upper-case letters and then sorts the list with lower-case letters after so if I had the following cat dog Bird Zebra it would sort it like

Bird
Zebra
dog
cat

so how do I ignore case so that dog and cat would come before Zebra but after Bird? Thank you for any help

like image 703
GFlam Avatar asked Aug 29 '26 13:08

GFlam


1 Answers

Use the built-in String comparator String.CASE_INSENSITIVE_ORDER

java.util.Collections.sort(path, String.CASE_INSENSITIVE_ORDER);
like image 142
squawknull Avatar answered Sep 01 '26 04:09

squawknull