Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

what data structure is good for this problem ?

 
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 ?
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like a good idea to me.
 
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.
    Bookmark Topic Watch Topic
  • New Topic