在Java中 ,如何创建一个Arraylist,并初始化为空?

如题所述

 public class Demo{
    public static void main(String arr[]){
        ArrayList list= new ArrayList();
    }
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-04-29
ArrayList list = new ArrayList();追问

为什么我这样写会有warning:The value of the local variable products is not used呢?
ArrayList products = new ArrayList();

追答

这是编译器警告,告诉你变量没有被使用。不应该声明一个不被使用的变量。就像不该买个什么用都没有的东西一样。

本回答被提问者采纳