黑马程序员技术交流社区

标题: 求解,看代码 [打印本页]

作者: xiaochen33520    时间: 2014-3-25 16:25
标题: 求解,看代码
本帖最后由 xiaochen33520 于 2014-3-26 13:19 编辑

                Comparator<Student> comp = Collections.reverseOrder();
                comp = Collections.reverseOrder(new ComparatorByMath());

                Set<Student> set = StudentInfoTool.getStudents(comp);
               
               
                File file = new File("stuinfo.txt");
                StudentInfoTool.write2File(set, file);

求解,红色字体的这两句代码有什么用?
作者: 疯狂沙漠    时间: 2014-3-25 16:42
ComparatorByMath这个是比较器对象,内部已经设定了一种排序方式,比如是按月份的从小到大顺序。使用Collections.reverseOrder(比较器对象),刚好和比较器内部的排序相反,也就是按月份的从大到小的顺序排列
作者: 李东梁    时间: 2014-3-25 17:44
  1. Comparator<Student> comp = Collections.reverseOrder();
复制代码

第一句:定义的一个比较器对象
  1. comp = Collections.reverseOrder(new ComparatorByMath());
复制代码

第二句:规定第一句定义的比较对象按月份的顺序进行排序比较
  1. Set<Student> set = StudentInfoTool.getStudents(comp);
复制代码

这句是安定义好的规则对set集合进行操作
作者: xiaochen33520    时间: 2014-3-26 13:19
哦 明白了3Q




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2