title: create generic tree with more than two child each may have unique proprties
body: <p>I have to create a generic tree.  It may have more than 2 children, and one child may act as a parent for the next level and another may not.(Not binary tree)
  I have tried using the below code.  The problem is, they are created by assuming all children may act as a parent.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  
  class Tree&lt;T&gt;
  {
  private T data;
  private Tree&lt;T&gt; parent;
  private List&lt;Tree&lt;T&gt;&gt; children;
  
  public Tree(T data)
  {
      this.data = data;
      children = new ArrayList&lt;Tree&lt;T&gt;&gt;();
  }
  
  /**
   * Adds a new child node to the parent node returns the added Child
   */
  public Tree&lt;T&gt; addChild(T childData)
  {
      Tree&lt;T&gt; childNode = new Tree&lt;T&gt;(childData);
      childNode.parent = this;
      this.children.add(childNode);
      return childNode;
  }
  
  
  
  /**
   * Returns the parent
   */
  public Tree&lt;T&gt; getRoot()
  {
      if (this == null)
      {
          return this;
      }
  
      Tree&lt;T&gt; parentTmp = this.parent;
      Tree&lt;T&gt; root = this;
  
      //iteration
      while (parentTmp != null)
      {
          parentTmp = root.parent;
          if (parentTmp != null)
          {
              root = parentTmp;
          }
  
      }
  
      return root;
  }
  
  
  @Override
  public String toString()
  {
      StringBuilder output = new StringBuilder("[");
      helpToString(this, output, 0);
      output.append("]");
      return output.toString();
  }
  
  private void helpToString(Tree&lt;T&gt; tree, StringBuilder output, int level)
  {
      if (tree == null)
          return; // Tree is empty, so leave.
  
      output.append(getSpaces(level) + tree.data);
  
      List&lt;Tree&lt;T&gt;&gt; children2 = tree.children;
      ++level; //increment the level
  
      Iterator&lt;Tree&lt;T&gt;&gt; iterator = children2.iterator();
      while (children2 != null &amp;&amp; iterator.hasNext())
      {
          Tree&lt;T&gt; next = iterator.next();
          if (next != null)
          {
              helpToString(next, output, level); //recursion
          }
  
      }
  
  }
  
  private String getSpaces(int level)
  {
      StringBuilder sb = new StringBuilder("\n");
      for (int i = 0; i &lt; level; i++)
      {
          sb.append("--");
      }
  
      return sb.toString();
  }
  
   }
  
  public class TreeTest
  {
  public static void main(String[] args)
  {
      Tree&lt;String&gt; root = new Tree&lt;String&gt;("A");
      root.addChild("B");
      Tree&lt;String&gt; childC = root.addChild("C");
      root.addChild("D");
  
      Tree&lt;String&gt; childC1 = childC.addChild("C1");
  
      System.out.println("root = " + childC.getRoot());                 // toString() method is invoked
                  // toString() method is invoked
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Output:</p>
  
  <pre><code>root = [
  A
  --B
  --C
  ----C1
  --D]
  </code></pre>
  
  <p>Here A is root having 3 children b,c,d, C is Parent for C1. For my scenario B having 2 properties, description and value, is that has to be hash map, and  C having 1 properties description , so it has to be arraylist. </p>
  
  <pre><code>A[Description]
  --B[Description,Value]
  --C[Description]
  ----C1[Description,Value]
  --D[Description,Value]]
  </code></pre>
  
  <p>So I have to create a generic tree that must have arraylist and hashmap.</p>
  
  <pre><code>Root[Description: root]
   -SubPart1[Description: SubPart1]
      ---- Description: SubPart1.1 and Value: 1.1 
      ---- Description: SubPart1.2 and Value: 1.2
  - Description: Root 1.1 and Value: 1.1
  - Description: Root 1.2 and Value: 1.2
  - Description: Root 1.3 and Value: 1.3
  -SubPart2[Description: SubPart2]
      ---- Description: SubPart2.1 and Value:2.1 
      ---- Description: SubPart2.2 and Value: 2.2
      ---- Description: SubPart2.3 and Value: 2.3
  - Description: Root 1.4 and Value: 1.4
  -SubPart3[Description: SubPart3]
      ---- Description: SubPart3.1 and Value:3.1 
  </code></pre>