Array List of String Sorting Method

后端 未结 6 520
小蘑菇
小蘑菇 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 11:06

    This'll do,

    Collections.sort(yourList, String.CASE_INSENSITIVE_ORDER);
    

    this is i have tried,

    ArrayList myList=new ArrayList();
    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]
    

提交回复
热议问题