Crouse[] crouse={new Crouse("2","语文"),new Crouse("3","数学")};
coursestoselect.addAll(Arrays.asList(crouse));
Crouse temp2=(Crouse)coursestoselect.get(2);
Crouse temp3=(Crouse)coursestoselect.get(3);
System.out.print("添加了课程:"+temp2.id+":"+temp2.name+"\n"+"添加了课程:"+temp3.id+":"+temp3.name+"\n");
Crouse[] crouse2={new Crouse("4","大文"),new Crouse("5","大学")};
coursestoselect.addAll(Arrays.asList(2,crouse2));
Crouse temp4=(Crouse)coursestoselect.get(2);
Crouse temp5=(Crouse)coursestoselect.get(3);
System.out.print("添加了课程:"+temp4.id+":"+temp4.name+"\n"+"添加了课程:"+temp5.id+":"+temp5.name+"\n");
}
2次输出的结果是一样的,第二个数组里面的根本就没有插入到列表啊?
coursestoselect.addAll(2,Arrays.asList(course2));
你的temp2 temp3 temp4 temp5都没有调用add方法,怎么会添加到列表里面呢?