title: Java collection query : creating array of mkdir commands
body: <p>I have a <code>LinkedHashSet</code> of <code>String</code> as below:</p>
  
  <pre><code>Set&lt;String&gt; dirSet = new LinkedHashSet&lt;String&gt;();
  </code></pre>
  
  <p>There are 12 <code>String</code> elements in above <code>Set</code> as below:</p>
  
  <pre><code>root/dir1/dir2/dir3/dir4/dir5/baseDir1/
  root/dir1/dir2/dir3/dir4/dir5/baseDir1/subDir/
  root/dir1/dir2/dir3/dir4/dir5/baseDir2/
  root/dir1/dir2/dir3/dir4/dir5/baseDir2/subDir/
  root/dir1/dir2/dir3/dir4/dir5/baseDir3/
  root/dir1/dir2/dir3/dir4/dir5/baseDir3/subDir/
  root/dir1/dir2/dir3/dir4/dir5/baseDir4/
  root/dir1/dir2/dir3/dir4/dir5/baseDir4/subDir/
  root/dir1/dir2/dir3/dir4/dir5/baseDir5/
  root/dir1/dir2/dir3/dir4/dir5/baseDir5/subDir/
  root/dir1/dir2/dir3/dir4/dir5/baseDir6/
  root/dir1/dir2/dir3/dir4/dir5/baseDir6/subDir/
  </code></pre>
  
  <p>I want to write a method to iterate through above <code>Set</code> in such a way that output of the method is a <code>String</code> <code>Array</code> containing commands to create above directory structure. </p>
  
  <p>Output <code>String</code> <code>Array</code> should contain <code>String</code> elements as below:</p>
  
  <pre><code>mkdir root/
  mkdir root/dir1/
  mkdir root/dir1/dir2/
  mkdir root/dir1/dir2/dir3/
  mkdir root/dir1/dir2/dir3/dir4/
  mkdir root/dir1/dir2/dir3/dir4/dir5/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir1/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir1/subDir/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir2/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir2/subDir/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir3/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir3/subDir/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir4/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir4/subDir/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir5/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir5/subDir/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir6/
  mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir6/subDir/
  </code></pre>
  
  <p>I am able to reach <code>dir5</code> level and then go one level in i.e. till <code>baseDir1/subDir/</code> by iterating through the Set and taking help of <code>String.split()</code> method to create tokens. </p>
  
  <p>However, I am not able to tackle when I again have to go a level up (baseDir2, baseDir3, etc.)</p>
  
  <p>How can I achieve this? </p>
  
  <p>Thanks for reading!</p>