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?

1
  • 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<String>(); // etc . Commented Jun 8, 2016 at 20:36

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.