title: Return list of Nodes a Tree in Java-Parent can have multiple child Nodes
body: <p>I am trying to write java code to return list of Nodes in a tree.
  The tree looks like <img src="https://i.stack.imgur.com/uQSxY.jpg" alt="this"> </p>
  
  <p>Node class is </p>
  
  <pre><code>class Node{
   String label;
   List&lt;Node&gt; children;
  }
  </code></pre>
  
  <p>I am trying this way. But not able to understand how to write a loop to traverse.</p>
  
  <pre><code>    public List&lt;Node&gt; returnAllNodes(Node node){
      List&lt;Node&gt; listOfNodes = 
          new ArrayList&lt;Node&gt;();
      boolean iterationCompleted = false;
      if(node==null){
          return null;
      }
      while(!iterationCompleted){
      if(node.getChildren()==null){
          listOfNodes.add(node);
                      break;    
      }
              else{
                 //
              }
      }
      return null;
      //return traverseAndReturnAllNodes(node.getChildren().get(0));
  }
  </code></pre>
  
  <p>Please help.</p>