We have a tree structure implemented using the DefaultMutableTreeNode
specified in Java.
Is there any way of traversing it, that is inbuilt?
If not, please suggest other techniques.
We have a tree structure implemented using the DefaultMutableTreeNode
specified in Java.
Is there any way of traversing it, that is inbuilt?
If not, please suggest other techniques.
If you mean you want to traverse the tree you can call breadthFirstEnumeration()
or depthFirstEnumeration()
in order to iterate over all nodes in the tree.
Example:
DefaultMutableTreeNode root = ...
Enumeration en = root.depthFirstEnumeration();
while (en.hasMoreElements()) {
// Unfortunately the enumeration isn't genericised so we need to downcast
// when calling nextElement():
DefaultMutableTreeNode node = (DefaultMutableTreeNode) en.nextElement();
}