Three Dimensional ArrayList?
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Is it possible to make a three dimensional ArrayList?
I never know what to put in my signature...
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Not directly. But you can box two Lists together for 2-dim list:
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Which needs another level for a 3d list:
Also, don't forget that unlike array initialization, you can't really specify a size. Instead, the outer list is empty by default, and you need to add new lists whenever you need them. What you can do is add null references:
And Ben, you can't declare a List<List<?>> and then assign to it a ArrayList<ArrayList<?>>; ArrayList<List<?>> will work fine though, and can have both ArrayList and LinkedList elements added.
Also, don't forget that unlike array initialization, you can't really specify a size. Instead, the outer list is empty by default, and you need to add new lists whenever you need them. What you can do is add null references:
And Ben, you can't declare a List<List<?>> and then assign to it a ArrayList<ArrayList<?>>; ArrayList<List<?>> will work fine though, and can have both ArrayList and LinkedList elements added.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Benjamin Winterberg
Ranch Hand
Posts: 36
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Arg typo, thanks for clarifying.
Jacob Steingart
Ranch Hand
Posts: 63
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
So you essentially make an ArrayList of Lists, and then assign your values to the list. Now that I think of it, I could probably just make an ArrayList of Arrays- I'm storing data in this, and I have a fixed number of columns, but a variable number of rows. Could you do this by saying something like
I believe I have usable code!
I believe I have usable code!
I never know what to put in my signature...
| Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |









