CourseToSelect.add(0, cr2);这里cr2不是在0位置了吗,为什么打印temp1还是cr1
public void TestAdd(){
Course cr1 = new Course("1","数据结构");
CourseToSelect.add(cr1);
Course temp = (Course)CourseToSelect.get(0);
System.out.println("添加课程:"+temp.getId()+":"+temp.getName());
Course cr2 = new Course("2","C语言");
CourseToSelect.add(0, cr2);
Course temp2 =(Course)CourseToSelect.get(0);
System.out.println("添加课程:"+temp.getId()+":"+temp.getName());
System.out.println("添加课程:"+temp2.getId()+":"+temp2.getName());
}
结果是:
添加课程:1:数据结构
添加课程:1:数据结构
添加课程:2:C语言