Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tree with duplicate keys

 
Vladimir Bezugliy
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you use any tree with duplicate keys?
What can I use from standard containers instead of it?

ps.
do not offer jgl.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Layne
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic