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

Two dimensional constructs

R Jarman
Greenhorn

Joined: Feb 08, 2005
Posts: 27
It's been a long time since I coded in Java. I need a two dimensional dynamic construct. I was thinking of using a vector where each member was another vector.

Maybe someone has a better solution. I have a list of items. These items have a type (A, B, C, etc). I want to parse the list of items into lists (vectors) of the same type. So my original list may have 100 items in it. Each item is of a particular type and I want to put that item into another list of like items so I can process each list of items separately. I can't hardcode 3 vectors for example because the number of item types is unknown. Can I use nested Vectors to simulate a "two dimensional array"? Can I access each item in the "array" with nested gets? Does anyone else have a better suggestion for a two dimensional dynamic construct?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I think that solution should work. But I would use ArrayList instead of Vector.

Vector is still supported in the language, but its use is discouraged now because its methods are synchronized.
R Jarman
Greenhorn

Joined: Feb 08, 2005
Posts: 27
So an arraylist can be dynamically allocated as well? I'm assuming without looking at the docs that I use an add and a get with an index so I can create an arraylist of arraylists and nest the gets?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Yes, just about anything you can do with a Vector, you can do with an ArrayList. Vector<E> implements the List<E> interface which ArrayList<E> implements.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two dimensional constructs