Solved

Colloection choice, which one is best for my problem

Posted on 2006-10-27
3
163 Views
Last Modified: 2012-05-05
I have been studing the collection material I could find on the webulator, My problem is as follows;

1, Class a (customers) containd a Cust_ID String and a customer name.
2, Class b (SalesOrder) contains details of sales orders including Cust_ID which has a one to many relationship with class a

I would like to create a data structure which contains both sets of data with class a as the key and class b as the
value(s).

I would like to be able to retrieve multiple instances of class b dependant on a value of class a.  I also want that class b is retrieved in a particular sequence (Document number)

I have looked at MAPs   but they want unique values.

I do not want anyone to write the code ,just a nudge in the right direction, I'm thinking TreeSets. Examples of code pertaining to nudging however will not be frowned upon.
0
Comment
Question by:ajackson99
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17820473
You need

Map<ClassA, List<ClassB>>;
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17820874
> I also want that class b is retrieved in a particular sequence (Document number)
Use TreeSet or PriorityQueue for bs
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 17823415
i'd go with:

Map<A, TreeSet<B>>;

make B implement Comparable ordering by doc number

http://java.sun.com/docs/books/tutorial/collections/index.html
http://javaalmanac.com/egs/java.util/coll_SortSet.html
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now