美文网首页
测试Comparable接口

测试Comparable接口

作者: wangzaiplus | 来源:发表于2017-06-24 16:02 被阅读0次

    package com.ctgu.test6_collection;

    import java.util.HashSet;
    import java.util.Set;

    public class Student implements Comparable<Student>{

    public String id;
    public String name;
    public Set<Course> courses;
    
    public Student(String id,String name){
        this.id = id;
        this.name = name;
        this.courses = new HashSet<Course>();
    }
    
    @Override
    public String toString() {
        return "Student [id=" + id + ", name=" + name + ", courses=" + courses + "]";
    }
    
    @Override
    public int compareTo(Student stu) {
    

    // return this.id.compareTo(stu.id);
    return this.name.compareTo(stu.name);
    }

    }

    相关文章

      网友评论

          本文标题:测试Comparable接口

          本文链接:https://www.haomeiwen.com/subject/zsekcxtx.html