Create an Array of Arraylists

636    Asked by DylanForsyth in SQL Server , Asked on Jul 6, 2021

 I am wanting to create an array of arraylist like below:

ArrayList[] group = new ArrayList()[4]

But it's not compiling. How can I do this?


Answered by himanshu

As per Oracle Documentation you should follow the below-mentioned code to solve java array of arraylists:

"You cannot create arrays of parameterized types"

Instead, you could do:

  ArrayList> group = new ArrayList>(4);

tackline, it is even better to do:

  List> group = new ArrayList>(4);


Your Answer

Interviews

Parent Categories