title: Java recursion and retain information
body: <p>I have a method that needs to loop through nested elements and return a string which should be concatenated as a result of the lopping through the tree. from searching, i believe recursion will be a easier method but I am unable to get the results desired. </p>
  
  <p>Structure of data:</p>
  
  <pre><code>root
    child 1
      child 1.1
      child 1.2
    child 2
      child 2.1
      child 2.2
        child 2.2.1
    child 3
  </code></pre>
  
  <p>Okay that is the idea. I need to loop though starting from a child to find the path to the root by list the element from the child starting point to the root.</p>
  
  <p>Eg: I am looking for child 2.2.1. The return answer should be: </p>
  
  <pre><code>child 2.2.1,child 2.2, child 2, root
  
  Private String loopthrough(String name, String needed LinkedList myList)
  
          List&lt;String&gt;Children = new ArrayList&lt;String&gt;();
          for (String child : children)
          {
  
              if (child.isParentOf(needed ))
              { name+=child.getName
               }
              else{
                  goneThrough.add(child);
              }
          }
          children = goneThrough;
  
          for (String child : children)
          {
              loopthrough(child);
          }
  </code></pre>