package demo;
import java.util.ArrayList;
import java.util.Comparator;
public class Test {
public Test() {
ArrayList aList = new ArrayList();
aList.add( "d ");
aList.add( "a ");
aList.add( "b ");
aList.add( "c ");
aList.add( "e ");
aList.sort();// 排序
System.out.println(aList);
}
public static void main(String[] args) {
Test one = new Test();
}
}
希望按 abcde 排序 . 为什么说sort()方法不可用啊?能给改下或者重新写个么 谢谢咯
------解决方案--------------------
建议你这样写:
import java.util.ArrayList;
import java.util.Arrays;
public class Test{
public static void main(String[] args){
ArrayList <String> a = new ArrayList <String> ();
a.add(new String( "b "));
a.add(new String( "c "));
a.add(new String( "a "));
a.add(new String( "d "));
String[] aa = new String[a.size];
a.toArray(aa);
Arrays.sort(aa);
for(String ee : aa){
System.out.print(ee+ " ");
}
}
}