Create an array of ArrayList elements

后端 未结 12 1954
遥遥无期
遥遥无期 2020-12-03 01:27

I want to create an array that contains ArrayList elements.

I\'ve tried

ArrayList name[] = new ArrayList()[];
         


        
12条回答
  •  旧时难觅i
    2020-12-03 01:35

    I know this is an old post, but someone just asked the same question and since nobody has mentioned the following solution, here it is.

    One way to get around it could be something like a 2d array (the recent question was about a 2d array or ArrayLists) of objects and then you should be able to put ArrayList references in the array. I have not tested it, but something like this should work.

    Object [][] data = new Object[5][5];
    data[0][0] = new ArrayList(); // etc . . .
    

提交回复
热议问题