【发布时间】:2012-10-14 08:02:01
【问题描述】:
我将Strings 随机放入ArrayList。
private ArrayList<String> teamsName = new ArrayList<String>();
String[] helper;
例如:
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.
鉴于您无法控制输入的事实(即进入 ArrayList 的字符串是随机的;斑马或龙以任何顺序排列),一旦 ArrayList 被输入填充,我如何按字母顺序对它们进行排序,不包括第一个?
teamsName[0] 没问题;按字母顺序对teamsName[1 to teamsName.size] 进行排序。
【问题讨论】:
-
使用 Collections.sort() 和 subList()
-
顺便说一句,为什么要排除第一个元素?我希望这不是因为第一个元素是像“团队名称”这样的标题元素......应该只在前端管理,然后过滤......
-
第一个元素是我团队的名字,所以我想把它作为第一个;它将在下拉菜单中,就像我们将美国作为第一个并按字母顺序排列其他国家/地区