aspose file tools*
The moose likes Beginning Java and the fly likes Three Dimensional ArrayList? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Three Dimensional ArrayList?" Watch "Three Dimensional ArrayList?" New topic
Author

Three Dimensional ArrayList?

Jacob Steingart
Ranch Hand

Joined: Mar 28, 2008
Posts: 63
Is it possible to make a three dimensional ArrayList?


I never know what to put in my signature...
Benjamin Winterberg
Ranch Hand

Joined: Sep 19, 2007
Posts: 36
Not directly. But you can box two Lists together for 2-dim list:



Hibernate DAOs with Spring | Separation of Concerns | Eclipse Code Templates | more...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Benjamin Winterberg
Ranch Hand

Joined: Sep 19, 2007
Posts: 36
Arg typo, thanks for clarifying.
Jacob Steingart
Ranch Hand

Joined: Mar 28, 2008
Posts: 63
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!
 
jQuery in Action, 2nd edition
 
subject: Three Dimensional ArrayList?