• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Three Dimensional ArrayList?

 
Jacob Steingart
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to make a three dimensional ArrayList?
 
Benjamin Winterberg
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not directly. But you can box two Lists together for 2-dim list:

 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Benjamin Winterberg
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arg typo, thanks for clarifying.
 
Jacob Steingart
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic