File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Which Data Structure to use?" Watch "Which Data Structure to use?" New topic
Author

Which Data Structure to use?

mayank gupta
Ranch Hand

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

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
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

Check out Apache Commons Collections. It has a MultiKeyMap.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10491
    
    9

Hardik,
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: http://aspose.com/file-tools
 
subject: Which Data Structure to use?