Arrays cannot be resolved 我是导入了ArraysList的这个包的,为什么我这里会一直有错误,请求大神指点
package collection.map.demo;
import java.util.ArrayList;
import java.util.List;
/*
* 备选课程类
*/
public class ListTest {
public List coursesToSelect;
/*
* 用于存放备选课程的容器List
*/
public ListTest(){
this.coursesToSelect=new ArrayList();
}
/*
* 用于往coursesToSelect中添加备选课程
*/
public void testAdd(){
//创建一个课程对象,并通过调用add方法,添加到备选课程List中
Course cr1=new Course("1","数据结构");
coursesToSelect.add(cr1);
Course temp=(Course) coursesToSelect.get(0);//强制转换,在List中取出的是object的对象
System.out.println("添加了课程:"+temp.id+": "+temp.name);
Course cr2=new Course("2","离散数学");
coursesToSelect.add(0,cr2);//传递进去的位置参数不能超过List的长度
Course temp2=(Course) coursesToSelect.get(0);
System.out.println("添加了课程:"+temp2.id+": "+temp2.name);
Course[] course={new Course("3","高等数学"),new Course("4","运筹学")};
coursesToSelect.addAll(Arrays.asList(course));
}
public static void main (String[]args){
ListTest lt=new ListTest();
lt.testAdd();
}
}
package collection.map.demo; import java.util.ArrayList; import java.util.List; /* * 备选课程类 */ public class ListTest { public List coursesToSelect; /* * 用于存放备选课程的容器List */ public ListTest(){ this.coursesToSelect=new ArrayList(); } /* * 用于往coursesToSelect中添加备选课程 */ public void testAdd(){ //创建一个课程对象,并通过调用add方法,添加到备选课程List中 Course cr1=new Course("1","数据结构"); coursesToSelect.add(cr1); Course temp=(Course) coursesToSelect.get(0);//强制转换,在List中取出的是object的对象 System.out.println("添加了课程:"+temp.id+": "+temp.name); Course cr2=new Course("2","离散数学"); coursesToSelect.add(0,cr2);//传递进去的位置参数不能超过List的长度 Course temp2=(Course) coursesToSelect.get(0); System.out.println("添加了课程:"+temp2.id+": "+temp2.name); Course[] course={new Course("3","高等数学"),new Course("4","运筹学")}; coursesToSelect.addAll(Arrays.asList(course)); } public static void main (String[]args){ ListTest lt=new ListTest(); lt.testAdd(); } }