• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which Data Structure to use?

 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to know what data structure to use in this case:
I have three values Type, Code and message. The combination of type, code is unique. I cannot use maps here, i realised.
The values of Type, Code and Message can be as follows <0200, 011, M1><0210, 011, M2> <0200, 033, M3> <0210, 033, M4>
Each time I want to retrieve the Messages using the values of both Type and Code.
Please suggest.
 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think use the simplest one ArrayList.
Make one class which consist all the three fields as member data.
And pass the object of class int it's add method.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the combination is unique then you could use a Set to store them. Because a Set doesn't allow duplicates.
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I store them in a ArrayList, i will have to retrieve it using an index. I want to retrieve 'message' using the combination of 'type' and 'code'
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out Apache Commons Collections. It has a MultiKeyMap.
 
Maneesh Godbole
Saloon Keeper
Posts: 11173
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hardik,
Please go easy on the colors as it makes the post difficult to read.
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
I finally did use MultiKey from the commons collections.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic