0

Possible Duplicate:
How to create multidemensional arraylist in Java?

I have been having trouble understanding if and how an multidimensional Arraylist can be created. I know that from an ArrayList objects can be added,removed,checked, etc. and can be made two dimensionally, but can it be made 3 dimensionally.

  • 2D ArrayList<object1,object2,object3>
  • 3D ArrayList<>?

I know a regular array can be multidimensional simply by int[][] adding another set of brackets, but does an ArrayList work the same way?

Community
  • 1
  • 1

2 Answers2

4

I believe you should just be able to make an array list of array lists.

ArrayList<ArrayList<String>> 

for example, if you want a 2D array list of strings.

Or go in for a third:

ArrayList<ArrayList<ArrayList<String>>> 

for a 3D array list.

mercurytw
  • 93
  • 1
  • 8
  • Ah I see, but is there a way to create an ArrayList that will accept both strings and integers? –  Jan 08 '13 at 21:53
  • ArrayList, and cast down to String or the special integer class, Integer when you pull the object out of the array list. – mercurytw Jan 08 '13 at 22:06
3

ArrayList<ArrayList<Integer>> is an ArrayList containing ArrayLists consisting of Integers, in other words, a 3d integer ArrayList.

  • Ah I see, but is there a way to create an ArrayList that will accept both strings and integers? –  Jan 08 '13 at 21:53