public class Student {
public String sid;
public String sname;
public Set<Course> courses;
public Student(String sid, String sname){
this.sid = sid;
this.sname = sname;
this.courses = new HashSet<Course>();
}
}
创建SetTest类
public class SetTest {
public List<Course> coursesToSelect;
public SetTest(){
coursesToSelect = new ArrayList<Course>();
}
}
在SetTest类中构建 添加元素的方法testAdd()
public void testAdd(){
Course cr1 = new Course("1","数据结构");
coursesToSelect.add(cr1);
Course cr2 = new Course("2","C语言");
coursesToSelect.add(0,cr2);
Course[] course = {new Course("3","离散数学"),new Course("4","汇编语言")};
coursesToSelect.addAll(Arrays.asList(course));
Course[] course2 = {new Course("5","高等数学"),new Course("6","大学英语")};
coursesToSelect.addAll(2,Arrays.asList(course2));
}