• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what data structure is good for this problem ?

 
steve francisco
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinking about a Giant food store product. Each has a product code associated with it. The food is grouped by big groups then by smaller groups. For example:

Milk (code: 01)
whole milk (code 01-11)
skim milk (code 01-12)
Bread (code: 02)
white bread (code 02-11)
.... (code 02-12)
Cheese (code: 03)
swiss cheese (code 03-11)
...

And for each product, we need its price, quantity, location, etc. User can pick from the lists and I need to display tables for the products they pick and it has to be grouped at the "2-digit" code level, i.e make a table for "milk" followed a table for "bread", etc.

I think of using "Hashmap" and the key is the "2-digit" code (like 01, 02, 03), for each key, there is an Arraylist associated with it. e.g. for "01" the arraylist includes few elements, each element includes the "4-digit" code, price, quantity. So when I print the tables, I iterate through the keys, for each key, I create a table displaying the Arraylist.

Is this a good idea or do you have better suggestion ?
 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like a good idea to me.
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your key contains just the code, how would you retrieve the big group name? from another look-up table?

How about having a POJO to have 2 instance variables: a String to contain the big group name & an ArrayList to contain elements.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic