本帖最后由 Up↑Lee↗ 于 2014-3-30 18:37 编辑
- class Student implements Comparable<Person
- {
- public int compareTo(Person s)
- {
- this.getName()
- }
- }
- */
- class Comp implements Comparator<Person>
- {
- public int compare(Person s1,Person s2)
- {
- //Person s1 = new Student("abc1");
- return s1.getName().compareTo(s2.getName());
- }
- }
- TreeSet<Student> ts = new TreeSet<Student>(new Comp());
- ts.add(new Student("abc1"));
- ts.add(new Student("abc2"));
- ts.add(new Student("abc3"));
复制代码
有关Comparable和Comparator比较器,这两个接口是相同的么??求解释
|