public class ListTest {
public List<Course> courseToSelect;
public ListTest()
{
this.courseToSelect=new ArrayList<Course>();
}
public void addTest()
{
Course[] cr1={new Course("2","化学"),new Course("1","数学")};
courseToSelect.addAll(cr1);
}
public void forEach()
{
for(Course cou:courseToSelect)
{
System.out.println("课程"+cou.id+":"+cou.name);
}
}
public static void main(String[] args)
{
ListTest it=new ListTest();
it.addTest();
it.forEach();
}
}
courseToSelect.addAll(Arrays.asList(cr1));
Course[] course2 = { new Course("5", "高等数学"), new Course("6", "大学英语") };
// 将一个数组转化为一个List对象,这个方法会返回一个ArrayList类型的对象
courseToSelect.addAll(2, Arrays.asList(course2));
数组要转化为List对象,然后再给出你想要插入的起始位置