Solved

How to use a nested TreeMap

Posted on 2003-11-25
6
486 Views
Last Modified: 2006-11-17
Hi,

I have data in the following form: Library Case Study example

String borrower, Object loanstate, Object loanitem.

I have many borrowers, loanstate is either borrowed or returned and the loanitem
would be say a bookitem.

What I would like to do is output in the form:

Borrower:      Borrowed       Book1
                              Book2
                              Book3
                              ..etc
               Returned       Book1
                              Book3

I thought maybe a nested TreeMap would allow me to do this i.e.

Key, (key, value)

borrower (loanstate, loanitem) would allow me to do this.

Any suggestions on how to code this up ?

Thanks

Drew
0
Comment
Question by:DrewAllan
  • 2
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 9817812
Your Borrower should be one entity. It should have a list of Books. One of the fields of Book should be loan state. The way you organise the collection of books is up to you. It could be a TreeMap keyed on the book's UID (ISBN)
0
 

Author Comment

by:DrewAllan
ID: 9817868
Can you give me an example of how to code it ?

Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9817886
Sorry - no. This is clearly class work and as such, it's against the Member Agreement to do this. We can certainly help with code you have already produced.
0
 

Author Comment

by:DrewAllan
ID: 9830355
Ok I can appreciate that but it was more an example of how to constuct it I was after.

How me suggesting an example of how to construct the Nested TreeMap

would it be

Map(index,[indexOuter,[[indexInner1, [value1, value2,... ],[indexInner22, [value22, value23,... ], [indexInner3, [value31, value32,... ],[indexInner4, [value42, value43,... ]..etc])

where index would be string object called Borrower and the outer nest value [index,[values]] would be say an ArrayList and then the inner nest values would be another ArrayList.

Do you think this would work or would there be a better way of doing it?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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
xampp tool 12 56
how to install java on RHEL image on EC2 4 41
Java: How do I open the default windows program for a given file type 3 39
CSV file parsing thru Java 13 34
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 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 tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

830 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