How can I sort an ArrayList of Strings in Java?

后端 未结 5 1106
遥遥无期
遥遥无期 2020-11-30 09:21

I have Strings that are put into an ArrayList randomly.

private ArrayList teamsName = new ArrayList();
         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 10:02

    Check Collections#sort method. This automatically sorts your list according to natural ordering. You can apply this method on each sublist you obtain using List#subList method.

    private List teamsName = new ArrayList();
    List subList = teamsName.subList(1, teamsName.size());
    Collections.sort(subList);
    

提交回复
热议问题