File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Which Data Structure to use? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Which Data Structure to use?" Watch "Which Data Structure to use?" New topic

Which Data Structure to use?

mayank gupta
Ranch Hand

Joined: Dec 21, 2008
Posts: 78

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

Joined: Jan 30, 2010
Posts: 252
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

Joined: Oct 25, 2008
Posts: 2700

If the combination is unique then you could use a Set to store them. Because a Set doesn't allow duplicates.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
mayank gupta
Ranch Hand

Joined: Dec 21, 2008
Posts: 78
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

Joined: Oct 27, 2005
Posts: 20279

Check out Apache Commons Collections. It has a MultiKeyMap.

How To Ask Questions How To Answer Questions
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10834

Please go easy on the colors as it makes the post difficult to read.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
mayank gupta
Ranch Hand

Joined: Dec 21, 2008
Posts: 78
Thank you.
I finally did use MultiKey from the commons collections.
I agree. Here's the link:
subject: Which Data Structure to use?
It's not a secret anymore!