老师好,数组下标越界问题,为什么老师的代码没有出现这一问题?还有怎么改呢?可不可以在前面加上异常处理啊??
Course[] course= {new Course("003","离散数学"),new Course("004","撒哈拉沙漠")};
coursesToSelect.addAll(Arrays.asList(course));//通过arrays实例将传入的数组转变为list
Course temp3=(Course) coursesToSelect.get(3);
Course temp4=(Course) coursesToSelect.get(4);
// System.out.println("\n"+"添加了两门课程:"+"\n"+"\t"+temp3.id+":"+"\t"+temp3.name+"\n"+"\t"+temp4.id+":"+"\t"+temp4.name+";");
Course[] course2= {new Course("005","小王子"),new Course("006","墨菲定理")};
coursesToSelect.addAll(2, Arrays.asList(course2));
Course temp5=(Course) coursesToSelect.get(2); //通过get方法取出所需元素
Course temp6=(Course) coursesToSelect.get(3);
// System.out.println("添加了两门课程:"+"\n"+"\t"+temp5.id+":"+"\t"+temp5.name+"\n"+"\t"+temp6.id+":"+"\t"+temp6.name+";");
}