• Post Reply Bookmark Topic Watch Topic
  • New Topic

looking for the right data structure for my set of ArrayLists  RSS feed

 
Stan Lederer
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a servlet I'm wanting to generalize but this is really a Java data structure question and not a servlet question.

Right now I've got an ArrayList:



I populate the ArrayList like this:



product is currently hardcoded.

I want to modify my servlet to use some sort of multi-dimensional structure to hold a set of ArrayLists so that I can populate and reference different sets of collectionNamesAndUrls arrayLists depending on what product is.

And, my servlet won't know what the different values are for product until it initializes the servlet. So, I think a standard multi-dimensional array would be clumsy. I think I want something like a list of ArrayLists where the first subscript is a hash.

Would someone please point me in the right direction.

Thanks.
 
bala nannaka
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to go for multimap implementation
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stan Lederer wrote:I think I want something like a list of ArrayLists where the first subscript is a hash.
Would someone please point me in the right direction.

Sounds like you may have answered it yourself:
HashMap<Product, List<String>>

Another thing to think about is that Java also has both URL (java.net.URL) and URI (java.net.URI) classes, so you might want a List<URL> (or URI) instead.

Winston
 
Stan Lederer
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, I'll play with your suggestions and report back.
 
Stan Lederer
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, again, for your help.

So, this is what I ended up doing:

My declaration:


My method to populate the HashMap:


My call to the method:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!