title: how to add the newline to the toString of the multi-tree
body: <p>There is a structure like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class TreeNode {
  
  private String key;
  private List&lt;TreeNode&gt; children;
      ....
  </code></pre>
  
  <p>}</p>
  
  <p>I override the toString() function</p>
  
  <pre><code>@Override
  public String toString() {
      String treeStructure = "TreeNode [key=" + key +  "]";
      if(children!=null){
          for(TreeNode child:children){
          treeStructure = treeStructure+"--- &gt;"+children.toString()+"/n";
          }
      }
      return treeStructure;
  }
  </code></pre>
  
  <p>Then I test the result:</p>
  
  <pre><code>public static void main(String[] args) {
      TreeNode node = new TreeNode();
      node.setKey("root");
      List&lt;TreeNode&gt; children = new ArrayList&lt;TreeNode&gt;();
      TreeNode child1 = new TreeNode();
      child1.setKey("child1");
      TreeNode child2 = new TreeNode();
      child2.setKey("child2");
      children.add(child1);
      children.add(child2);
      List&lt;TreeNode&gt; grandchildren = new ArrayList&lt;TreeNode&gt;();
      TreeNode grandchild = new TreeNode();
      grandchild.setKey("grandchild");
      grandchildren.add(grandchild);
  
      node.setChildren(children);
      child1.setChildren(grandchildren);
  
      System.out.println(node);
  
  }
  </code></pre>
  
  <p>But when I run it the output is:</p>
  
  <pre><code>TreeNode [key=root]---&gt;[TreeNode [key=child1]---&gt;[TreeNode [key=grandchild]]/n, TreeNode [key=child2]]/n---&gt;[TreeNode [key=child1]---&gt;[TreeNode [key=grandchild]]/n, TreeNode [key=child2]]/n
  </code></pre>
  
  <p>How can I add the newline in the output like this:</p>
  
  <pre><code>TreeNode [key=root]---&gt;TreeNode [key=child1]---&gt;TreeNode [key=grandchild]
                     ---&gt;TreeNode [key=child2]
  </code></pre>
  
  <p>But now the child1 showed twice and the newline wasn't added in the result.</p>
  
  <p>================================
  I changed the function：</p>
  
  <pre><code>@Override
  public String toString() {
      String treeStructure = "TreeNode [key=" + key +  "]";
      if(children!=null){
          for(TreeNode child:children){
          treeStructure = treeStructure+"\n"+"--&gt;"+children.toString()+"\n";
          }
      }
      return treeStructure;
  }
  </code></pre>
  
  <p>then the output is:</p>
  
  <pre><code>TreeNode [key=root]
  ---&gt;[TreeNode [key=child1]
  ---&gt;[TreeNode [key=grandchild]]
  , TreeNode [key=child2]]
  
  ---&gt;[TreeNode [key=child1]
  ---&gt;[TreeNode [key=grandchild]]
  , TreeNode [key=child2]]
  </code></pre>
  
  <p>why the child repeated twice and where is the "," from?</p>