| Author |
Multidimensional ArrayList
|
Chris Cairns
Ranch Hand
Joined: Jan 31, 2003
Posts: 48
|
|
|
What is the syntax for creating a multidimensional ArrayList?
|
 |
Jon Dornback
Ranch Hand
Joined: Apr 24, 2002
Posts: 137
|
|
create an array list, then add an array list to it as the object. to add an object in to the matrix, you have to get the array list at that row, type cast it back to an ArrayList (because array list only holds type Object), then add something to that array list. to access the objects held by the matrix, you get the appropriate row, type cast that row to an ArrayList, then get the appropriate column and type cast that column back to the appropriate object (in this case String). also note that the matrix doesn't have to be square - it can have rows of differing lengths. [ April 02, 2003: Message edited by: Jon Dornback ]
|
use the [CODE] tags - it makes it much easier for people to help you.
|
 |
corrado martini
Greenhorn
Joined: May 27, 2010
Posts: 14
|
|
Jon Dornback wrote:
create an array list, then add an array list to it as the object. to add an object in to the matrix, you have to get the array list at that row, type cast it back to an ArrayList (because array list only holds type Object), then add something to that array list. to access the objects held by the matrix, you get the appropriate row, type cast that row to an ArrayList, then get the appropriate column and type cast that column back to the appropriate object (in this case String).
also note that the matrix doesn't have to be square - it can have rows of differing lengths.
[ April 02, 2003: Message edited by: Jon Dornback ]
Many thanks, Java Ranch is the greatest
|
 |
Andreas Hollmann
Greenhorn
Joined: Jan 06, 2010
Posts: 27
|
|
|
If you want create a matrix I advice ArrayTable of google guava libraries.
|
 |
 |
|
|
subject: Multidimensional ArrayList
|
|
|