java中的集合框架目录结构创建学生类和课程类课程类/imooc_collection_map_demo/src/com/imooc/collection/Course.javapackage com.imooc.collection;//课程类public class Course { public String id; public String name; public Course(String id, String name) { this.id = id; this.name = name; }}学生类/imooc_collection_map_demo/src/com/imooc/collection/Student.javapackage com.imooc.collection;//学生类import java.util.HashSet;import java.util.Set;public class Student { public String id; public String name; public Set courses; public Student(String id ,String name) { this.id = id; this.name = name; this.courses = new HashSet(); }}添加课程添加的方法/imooc_collection_map_demo/src/com/imooc/collection/ListTest.javapackage com.imooc.collection;import java.util.ArrayList;import java.util.List;public class ListTest { //用于存放备选课程的List public List coursesToSelect; public ListTest() { this.coursesToSelect = new ArrayList(); } //用于往coursesToSelect中添加备选课程 public void testAdd() { //创建一个课程对象,并通过调用add方法,添加到备选课程list中 Course cr1 = new Course(“1”, “数据结构”); coursesToSelect.add(cr1); Course temp = (Course) coursesToSelect.get(0); System.out.println(“添加了课程:” + temp.id + “:” + temp.name); Course cr2 = new Course(“2”, “c语言”); coursesToSelect.add(0, cr2); Course temp2 = (Course) coursesToSelect.get(0); System.out.println(“添加了课程:” + temp2.id + “:” + temp2.name); } public static void main(String[] args) { ListTest lt = new ListTest(); lt.testAdd(); }}数组下标越界异常/imooc_collection_map_demo/src/com/imooc/collection/ListTest.javapackage com.imooc.collection;import java.util.ArrayList;import java.util.List;public class ListTest { //用于存放备选课程的List public List coursesToSelect; public ListTest() { this.coursesToSelect = new ArrayList(); } //用于往coursesToSelect中添加备选课程 public void testAdd() { //创建一个课程对象,并通过调用add方法,添加到备选课程list中 Course cr1 = new Course(“1”, “数据结构”); coursesToSelect.add(cr1); Course temp = (Course) coursesToSelect.get(0); System.out.println(“添加了课程:” + temp.id + “:” + temp.name); Course cr2 = new Course(“2”, “c语言”); coursesToSelect.add(0, cr2); Course temp2 = (Course) coursesToSelect.get(0); System.out.println(“添加了课程:” + temp2.id + “:” + temp2.name); Course cr3 = new Course(“3”, “test”); coursesToSelect.add(-1,cr3); Course cr3 = new Course(“3”, “test”); coursesToSelect.add(4,cr3); } public static void main(String[] args) { ListTest lt = new ListTest(); lt.testAdd(); }}