Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Colloection choice, which one is best for my problem

Posted on 2006-10-27
3
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 750 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses

618 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