File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Tree with duplicate keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Tree with duplicate keys" Watch "Tree with duplicate keys" New topic

Tree with duplicate keys

Vladimir Bezugliy
Ranch Hand

Joined: Sep 29, 2004
Posts: 33
Do you use any tree with duplicate keys?
What can I use from standard containers instead of it?

do not offer jgl.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The Java Collections Framework does not offer a Tree class. However, there are tree implementations of some of the collections that ARE available. These include TreeSet and TreeMap.

However, to answer your question, one possible solution is to use a Map (either HashMap or TreeMap) where the value associated with each key is a List (or Map or Set or any other Collection). You can add the multiple values associated with the key to the List then add the List to the Map.

You may find it helpful to go through the Collections trail in Sun's Java Tutorial. Also, the Java API documentation is a great reference when looking for classes and methods to accomplish a specific task. You should familiarize yourself with the documentation. IMO, learning to navigate it is an essential skill when programming in Java.

I hope this helps get you headed in the right direction. Good luck!


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Tree with duplicate keys
It's not a secret anymore!