testAdd里面可以取到courseToSelect的值,testGet里面为空
private List<Course> courseToSelect;
public ListTest(){
this.courseToSelect=new ArrayList<Course>();
}
/*
* 用于往courseToSelect添加备选课程
*/
public void testAdd(){
Course cs = new Course("1", "数据结构");
courseToSelect.add(cs);
Course[] course = {new Course("2","高数"),new Course("3","英语")};
courseToSelect.addAll(Arrays.asList(course));
Course[] course2 = {new Course("4","java"),new Course("5","android")};
courseToSelect.addAll(3,Arrays.asList(course2));
//Course temp = courseToSelect.get(3);
//System.out.println("课程:"+temp.getId()+temp.getName());
}
public void testGet(){
System.out.println("待选课程:");
for(int i=0;i<courseToSelect.size();i++){
Course co = courseToSelect.get(i);
System.out.println("课程:"+co.getId()+":"+co.getName());
}
}
public static void main(String[] arge){
ListTest lt = new ListTest();
lt.testGet();
lt.testAdd();
}