使用java方法按字母顺序组织列表
List <String> cdList = new ArrayList();
Collections.addAll(cdList, "ExampleG","ExampleB","ExampleR","ExampleX");
bigBox.append("Original Order\n**************\n");
for (String s : cdList) {
bigBox.append(s);
bigBox.append("\n");
}
bigBox.append("\n\nSorted Order\n************\n");
for (String s : cdList) {
bigBox.append(s);
bigBox.append("\n");
}
我需要按字母顺序组织列表,并将其显示在“排序顺序”下方,但也需要保留原始顺序,以便在原始订单行下使用
# 1 楼答案
你不能将不同的订单保存在同一个列表中
如果适用,我强烈建议您使用泛型
# 2 楼答案
原始清单:
已排序列表:
现在您可以迭代
cdList
和sorted
,并将它们附加到bigBox
:好了