0

How can I define in Java a Matrix of ArrayList< String>.

I am trying with:

Arraylist<String>[][] data =new ArrayList<String>[5][5];

But that throws this error:

Cannot create a generic array of ArrayList

Any idea?

overflow13
  • 21
  • 4
  • I realize this might be a duplicate, but here is a solution that might work better than the accepted answer on the duplicate post : Generic type array is not allowed. One way to get around it could be something like a 2d array of objects and then you should be able to put ArrayLists 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 . – Sanjeev Jun 08 '16 at 20:36

1 Answers1

0

This is not allowed in Java, why dont you try and use nested ArrayList like this ArrayList<ArrayList<String>>.

Seek Addo
  • 1,791
  • 2
  • 16
  • 30