Existing implementations of trees in Java?
I am looking for any implementation of pure Tree data structure for Java (which are not graphical in java.awt), preferably generic.
With a shared tree, I would like to add items that shouldn't be sorted and do something like this:
TreeNode anotherNode = new TreeNode();
node.add(anotherNode);
... and then I would like to traverse the nodes (so that I can save and save the structure to a file when I load the tree again from the same file).
Does anyone know what implementations exist or is there any other idea to achieve this?
source to share
You can use the DefaultMutableTreeNode defined in the package javax.swing.tree
. It contains methods getUserObject()
and setUserObject(Object)
that allow you to attach data to each node tree. It allows an arbitrary number of child nodes for each parent, and provides methods for iterating through the tree using the width or depth ( breadthFirstEnumeration()
/ depthFirstEnumeration()
) method .
Also note that, although resident in the package javax.swing.tree
, this class does not contain any user interface code; This is just a basic model JTree
.
source to share