7

I am trying to create a Tree like structure were i have a root node and then i can add childrens to the root node and continue the process. I am not really interested in sorting. All i want is a tree like structure since i am creating an Org Chart.

Is there an exisitng java library that will let me add root node, child node or for example get a child node from a tree and then add child to those nodes as well. Or maybe get all the leaf node from a tree.

I am trying to avoid creating one on my own just to save time ? Any libraries you can suggest will be of great help .

Note: I am not using Swing or AWT components.

2
  • 3
    Try look at java TreeSet Commented Apr 11, 2014 at 12:28
  • @RMachnik That's a Set implemented with an underlying tree, not really a useful tree :) I'd suggest implementing one, it's just a matter of having a node class with a payload field and a list of children of the same class, plus a couple methods for manipulating it Commented Jun 7, 2021 at 8:32

1 Answer 1

5

The TreeModel interface in Java is designed for this. DefaultTreeModel supports adding any number of children to a node, listening on a node, and looking up nodes by path.

Sign up to request clarification or add additional context in comments.

1 Comment

DefaultTreeModel is very nice, but it can not be used in Android projects.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.