Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an ArrayList be a two-dimensional array?

I'm brand new to Java, programming, and StackOverflow. I need to use a list where I can add or remove things and don't know the initial size (like ArrayList) but I also need it to be two dimensional. I've read on Google and StackOverflow and I can't find a concrete answer. Is this a possibility? And if not can you point me in the right direction? Thanks in advance.

like image 377
Punkrockie Avatar asked Feb 22 '23 09:02

Punkrockie


2 Answers

ArrayList<ArrayList> arrList2D = new ArrayList<ArrayList>(2);

arrList2D.add(new ArrayList());
arrList2D.add(new ArrayList());

arrList2D is a 2D ArrayList.

like image 148
Azodious Avatar answered Feb 23 '23 21:02

Azodious


well you can always try writing a simple code and see if this work. By the way you can use Array list in array list and I am pretty sure it will be a very bad idea.

like image 38
Geek Avatar answered Feb 23 '23 22:02

Geek