• Post Reply Bookmark Topic Watch Topic
  • New Topic

What type of data structure to use?  RSS feed

 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two classes
Module & Modules.
Modules is a group of 'module'

It is very confusing how to structure Modules after googling collections, lists, and array lists and such.

There will never be a different type of object in Modules

Should I structure Modules as an array list or some sort of collection?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you need to do with your collection? is sorting/ordering it more important, or speed of access?  What about adding/deleting elements? These are what you should think about when deciding which collection to use.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding and deleting is most important.
These will be small groups so speed is not an issue.
Sorting not important
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How will you delete a Module from your Collection?  By name?  Are names unique?  By ID?
If there is something unique to every Module, a Map like HashMap is a good structure.  Otherwise try a Listlike ArrayList.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Modules have a unique id
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will try a hash map. Haver never done that before.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven Greenbaum wrote:I have two classes
Module & Modules.

I think it is a mistake to have such classes together. One needs to be renamed to something different or go out and have only list of module classes or an array of module classes.
Wagon x 12 makes Train. But Wagon x 12 to have class Wagons I think isn't very correct.

 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i.e.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!