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.

user3398326
  • 534
  • 2
  • 8
  • 25
  • 3
    Try look at java `TreeSet` – RMachnik Apr 11 '14 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 – Unai Vivi Jun 07 '21 at 08:32

1 Answers1

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.

Russell Zahniser
  • 16,188
  • 39
  • 30