Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two dimensional constructs

 
R Jarman
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic