title: Adding new layer of children in a Tree
body: <p>I'm making a Tree and have been able to implement setting the Parent and child properly. I'm stuck at attempting to make a new layer of the tree, a grandchild in this case. It isn't a binary tree. Ideally I'd like to place the implementation of the new layer in either the constructor or in the addChild method. The following is what I have for my set up and the methods setting up my Parent and Children in my Tree </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  public abstract class TreeNode {
  
  static int count; // store # tree nodes created. Generate IDs
  
  private String id;// unique id # of nodes.
  
  private List&lt;TreeNode&gt; children; // store all children of node
  
  private TreeNode parent; // reference parent of the node. Null is node is root
  
  public TreeNode(List&lt;TreeNode&gt; children) {
  
      this.children = children;
      this.count++;
      this.id = Integer.toString(this.count);
      int ctr = 0;
      if (children != null) {
          while (ctr &lt; children.size()) {
              children.get(ctr).setParent(this);
              ctr++;
          }
      }
  }
  
  public void addChild(TreeNode child) { // add single child to current node
  
      if (this.getChildren() == null) {
          child.setParent(this);
          this.setChildren(new ArrayList&lt;TreeNode&gt;());
          this.children.add(child);
      }
  
      else {
          child.setParent(this);
          this.children.add(child);
      }
  
  }
  </code></pre>