• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multidimensional ArrayList

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the syntax for creating a multidimensional ArrayList?
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want create a matrix I advice ArrayTable of google guava libraries.
reply
    Bookmark Topic Watch Topic
  • New Topic