title: Java: Turning Strings into a tree
body: <p>I have a sorted list of Strings that are directories, that I need to display as a tree.</p>
  
  <p>For example, if I have these strings:</p>
  
  <pre><code>"folder a/folder b/file 1"
  "folder a/folder b/file 2"
  "folder a/folder c"
  </code></pre>
  
  <p>I need to display them as:</p>
  
  <pre><code>folder a
  |- folder b
  |  |- file 1
  |  |- file 2
  |- folder c
  </code></pre>
  
  <p>I'm currently thinking about going through the list and keeping track of "parent folder" (ie. "folder a/folder b" for the first string) and build the tree depending on if the "parent folder" is the same. This seems quite complicated in moving back through the parent folders and I was wondering if anyone could recommend an easier/more efficient way of doing this?</p>
  
  <p>Would it help to iterate through the strings and actually build a tree first, and then iterate through the tree before displaying it? It might be worth noting that all data is saved as Strings (this tree would not be saved) therefore this requires me to build the tree data structure every time I want to display it.</p>