Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What java datastructure/library do you use for a Tree [closed]

I have a Region Hierarchy(think State, District, Taluk, etc) that I need to represent using a Tree. I saw a few implementations of a Tree in the public domain BUT not sure how good they are and how well they are maintained. Apache Collections doesn't have one of those NOR do the google collections. I'm wondering if any of you can point me to an implementation of a Tree in Java(with generics).

Thank you,

Update I am looking for a Tree Datastructure, preferably implemented using Generics : well tested.

like image 551
anjanb Avatar asked Jul 12 '10 16:07

anjanb


2 Answers

Check out DefaultMutableTreeNode. It's not generic, but otherwise seems to fit the bill. Even though it's in the javax.swing package, it doesn't depend on any AWT or Swing classes. In fact, the source code actually has the comment // ISSUE: this class depends on nothing in AWT -- move to java.util?

like image 191
Mark Avatar answered Nov 15 '22 10:11

Mark


Implementing a tree using generics is pretty simple, why not give it a try yourself? If you're not comfortable with generics, you can try declaring a tree that contains elements that implement an interface, then just have all your various region elements implement that interface.

like image 30
TMN Avatar answered Nov 15 '22 11:11

TMN