Java question about ArrayList[] x

后端 未结 6 1567
臣服心动
臣服心动 2021-02-06 08:41

I have always had this one issue with arrays of ArrayLists. Maybe you can help.

//declare in class
private ArrayList[] x;

//in constructor
x=new          


        
6条回答
  •  难免孤独
    2021-02-06 09:12

    I think you cannot make array of generic arraylist because no generic information will be available at runtime.Instead you can do like this:

    List[] arr=new ArrayList[30];
    arr[0]=new ArrayList();//create new arraylist for every index.
    

提交回复
热议问题