我怎么能进行排序字符串在Java中的ArrayList? [英] How can I sort an ArrayList of Strings in Java?
本文介绍了我怎么能进行排序字符串在Java中的ArrayList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有被放入字符串
秒的的ArrayList
随机
私人的ArrayList<串GT; teamsName =新的ArrayList<串GT;();
的String []帮手;
例如:
teamsName.add(辅助[0]),其中帮手[0] =龙;
teamsName.add(辅助[1]),其中辅助[1] =斑马;
teamsName.add(辅助[2]),其中辅助[2] =老虎//等等直到约150串。
鉴于这一事实,你无法控制(即正进入ArrayList是随机的,即串;以任何顺序斑马或龙)的输入,一旦装满输入ArrayListis,我该如何对它们进行排序按字母顺序排除了第一个?
teamsName [0]
的罚款;排序 teamsName [1至teamsName.size]
按字母顺序排列。
解决方案
Collections.sort(teamsName.subList(1,teamsName.size()));
在code以上将反映您整理原始列表的实际子表
I have String
s that are put into an ArrayList
randomly.
private ArrayList<String> teamsName = new ArrayList<String>();
String[] helper;
For example:
teamsName.add(helper[0]) where helper[0] = "dragon";
teamsName.add(helper[1]) where helper[1] = "zebra";
teamsName.add(helper[2]) where helper[2] = "tigers" // and so forth up to about 150 strings.
Given the fact that you cannot control the inputs (i.e. string that is coming into the ArrayList is random; zebra or dragon in any order), once the ArrayListis filled with inputs, how do I sort them alphabetically excluding the first one?
teamsName[0]
is fine; sort teamsName[1 to teamsName.size]
alphabetically.
解决方案
Collections.sort(teamsName.subList(1, teamsName.size()));
The code above will reflect the actual sublist of your original list sorted.
这篇关于我怎么能进行排序字符串在Java中的ArrayList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文