Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Two dimensional constructs

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic