public class ScannerDemo {
public static void main(String[] args) throws IOException{
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 IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while((line =br.readLine())!=null ){
System.out.println("请输入您要排序的字符串:");
if("end".equals(line)){
break;
//al.add(line);
}else{
al.add(line);
}
}
br.close();
}
} |
|