Solved

Colloection choice, which one is best for my problem

Posted on 2006-10-27
3
173 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 83
map related example 6 55
java imports not found 4 26
junit as external jar or library 7 22
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:

860 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