aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Multidimensional ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Multidimensional ArrayList" Watch "Multidimensional ArrayList" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multidimensional ArrayList