我可以在此示例中使用集合或列表吗?

Iam*_*MAN 4 java collections hibernate list

public class Student implements java.io.Serializable {

private long studentId;
private String studentName;
private Set<Course> courses = new HashSet<Course>(0);

public Student() {
}

public Student(String studentName) {
    this.studentName = studentName;
}

public Student(String studentName, Set<Course> courses) {
    this.studentName = studentName;
    this.courses = courses;
}

public long getStudentId() {
    return this.studentId;
}

public void setStudentId(long studentId) {
    this.studentId = studentId;
}

public String getStudentName() {
    return this.studentName;
}

public void setStudentName(String studentName) {
    this.studentName = studentName;
}

public Set<Course> getCourses() {
    return this.courses;
}

public void setCourses(Set<Course> courses) {
    this.courses = courses;
}
Run Code Online (Sandbox Code Playgroud)

}

他们在这里使用Hashset来获取课程.我怀疑是否可以使用列表来获取这些课程.我在互联网上读到列表以指定顺序获取vaues并允许列表中的重复项.而在集合中它没有任何订单,也不会允许重复.我想知道我应该在哪里使用集合和列表?谁有人建议?

NG.*_*NG. 6

感觉你已经回答了自己的问题.如果您需要项目集合,并且您希望项目集合没有重复项,请使用集合.您可以使用SortedSet强制排序.

如果允许您的集合具有重复项,则可以使用List.我认为在你的例子中,一个集合起作用,因为学生可能永远不会两次相同的课程.