Is there any standard Java library class to represent a tree in Java?
Specifically I need to represent the following:
Here:
public class Tree {
private Node root;
public Tree(T rootData) {
root = new Node();
root.data = rootData;
root.children = new ArrayList>();
}
public static class Node {
private T data;
private Node parent;
private List> children;
}
}
That is a basic tree structure that can be used for String
or any other object. It is fairly easy to implement simple trees to do what you need.
All you need to add are methods for add to, removing from, traversing, and constructors. The Node
is the basic building block of the Tree
.