A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 542826323 中级黑马   /  2016-2-20 15:46  /  546 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

各位大神,如下代码为什么输入的之后打印出来字符串的顺序没有任何变化:
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();
        }
}

1 个回复

正序浏览
有变化啊,倒序排列
输入:a
          b
          c
          over
显示:c
          b
          a
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马