Array List of String Sorting Method

后端 未结 6 523
小蘑菇
小蘑菇 2021-01-12 10:39

i have an Array List with Following values

ArrayList [Admin,Readonly,CSR,adminuser,user,customer]

when i used

Collections.s         


        
6条回答
  •  南笙
    南笙 (楼主)
    2021-01-12 10:48

    public class SortIgnoreCase implements Comparator {
        public int compare(Object o1, Object o2) {
            String s1 = (String) o1;
            String s2 = (String) o2;
            return s1.toLowerCase().compareTo(s2.toLowerCase());
        }
    }
    
    
    

    then

    Collections.sort(ArrayList, new SortIgnoreCase());
    

    提交回复
    热议问题