Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
0
You'll probably need to create some sort of Node class to represent the nodes in the tree: public class Node { private List<Node> children = null; private String value; public Node(String value) { this.children = new ArrayList<>(); this.value = value; } public void addChild(Node child) { children.add(child); } } Then to populate your tree: public static void main(String [] args) { Node root = new Node("root"); root.addChild(new Node("child1")); root.addChild(new Node("child2")); //etc. }
27th Dec 2016, 2:32 PM
guizani mahmoud
guizani mahmoud - avatar