Create an array of ArrayList elements

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

I want to create an array that contains ArrayList elements.

I\'ve tried

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


        
12条回答
  •  北海茫月
    2020-12-03 01:47

    Array of ArrayLists, example with Loops

    //Declare
    Object[] arrayLists = new Object[size];    
    
    //Fill
    for (int j=0; j < size; j++) {
         arrayLists[k]= generateAnArrayList(j);  //or whatnot
    }
    
    //Usage
    for (int j=0; j < size; j++) {
        ArrayList al = (ArrayList) arrayLists[j];
        //do something here
    }
    

提交回复
热议问题