i have an Array List with Following values
ArrayList [Admin,Readonly,CSR,adminuser,user,customer]
when i used
Collections.sort(ArrayList)
i'm getting the Following Result
[Admin,CSR,Readonly,adminuser,customer,user]
as per the Java doc the above results are correct, but my Expectation is (sorting irrespective of case (upper / lower case)
[Admin,adminuser,CSR,customer,Readonly,user]
provide an help how will do the sorting irrespective of case in java, is there any other method available
Note: i will do an Automate test for checking the sorting order in the Web table
regards
prabu
This'll do,
Collections.sort(yourList, String.CASE_INSENSITIVE_ORDER);
this is i have tried,
ArrayList<String> myList=new ArrayList<String>();
Collections.addAll(myList,"Admin","Readonly","CSR","adminuser","user","customer");
System.out.println(myList);
Collections.sort(myList, String.CASE_INSENSITIVE_ORDER);
System.out.println(myList);
the following output i got,
[Admin, Readonly, CSR, adminuser, user, customer]
[Admin, adminuser, CSR, customer, Readonly, user]
You can use your own comparator like this to sort irrespective of case (upper / lower case)
Collections.sort(list, new Comparator<String>() {
@Override
public int compare(String s1, String s2)
{
return s1.compareToIgnoreCase(s2);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With