日期:2014-05-20 浏览次数:21010 次
List<String> alllist = null; //定义list对象
List<String> allCollection=null; //
alllist = new ArrayList <String>(); // 实例化list对象,只能是STRING类型
allCollection = new ArrayList<String>();//实例化collection,只能是String类型
alllist.add("hello"); //从collection继承的方法
alllist.add(0,"world");//此方法为list扩充的方法
System.out.println(alllist);
allCollection.add("hello"); //从collection继承的方法
allCollection.add(0,"world");//此方法为list扩充的方法
System.out.println(allCollection);
}
------解决方案--------------------
主要错误有几大类:
1、是不应该在类里面直接写语句,语句必须放在函数中;
2、只有static变量,才能直接访问;
3、没见过的类;
4、不知道你有没有import所需要使用的类;
5、各种神奇的大小写错误。
比如:
import java.util.*;
public class Arraylistdemo01{
static List<String> alllist = null; //定义list对象
public static void main(String[] args) {
alllist = new ArrayList <String>();// 实例化list对象,只能是STRING类型
// Allcollection = new arraylist<String>();//实例化collection,只能是String类型
alllist.add("hello"); //从collection继承的方法
alllist.add(0,"world");//此方法为list扩充的方法
System.out.println(alllist);
}
}