package CourseToSelect;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ListTest {
List<Course> coursesToSelect ;
public ListTest(){
coursesToSelect = new ArrayList<Course>();
}
public void Add(){
Course cr1 = new Course("1","数据结构");
coursesToSelect.add(cr1);
Course temp;
Course course[] = {new Course("2","C语言"),new Course("3","高数") };
temp = (Course)coursesToSelect.get(0);
System.out.println("添加了课程:"+temp.ID+":"+temp.Name);;
}
public static void main(String[] args) {
ListTest lt = new ListTest();
//lt.Add();
Iterator<Course> it = lt.coursesToSelect.listIterator();
while(it.hasNext()){
Course temp = (Course)it.next();
System.out.println("添加了课程:"+temp.ID+":"+temp.Name); }
}
}
为什么运行不出结果呢?????真是令人疑惑
是的哦,狼若回头必有缘由,运行时看报错,仔细分析肯定会找到原因的
忘了。方法被注视了
加上了还是没有打印结果
coursesToSelect.addAll(Arrays.asList(course));