各位大神,如下代码为什么输入的之后打印出来字符串的顺序没有任何变化:
public class Demo {
public static void main(String[] args) throws Exception {
ArrayList<String> al = new ArrayList<String>();
getArrayList(al);
Comparator<String> c = Collections.reverseOrder();
Collections.sort(al, c);
for(String str:al){
System.out.println(str);
}
}
private static void getArrayList(ArrayList<String> al) throws Exception {
System.out.println("请输入您需要排序的字符串:");
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while((line=bf.readLine())!=null){
if("over".equals(line)){
break;
}else{
al.add(line);
}
}
bf.close();
}
} |
|