title: Finding all possible combinations within a String using permutation
body: <p>I currently have two methods which uses recursion to give me all of the possible combinations of a given <code>String</code>, I got to this with the help of this <a href="https://stackoverflow.com/questions/4240080/generating-all-permutations-of-a-given-string">answer</a>. So if I entered the <code>String</code> and it returns these combinations: </p>
  
  <pre><code>and
  adn
  dan
  dna
  nad
  nda
  </code></pre>
  
  <p>However I want it to return all possible combinations of the rest of even one/two letters in that string like so:</p>
  
  <pre><code>a
  n
  d
  an
  ad 
  na
  nd
  etc...
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/15103545/calculating-all-possible-combinations-of-a-string-with-a-twist">Something like this answer but in java</a></p>
  
  <p>That answer also mentioned and linked <a href="http://www.mathsisfun.com/sets/power-set.html" rel="nofollow noreferrer">Powersets</a> which showed all possible subsets of a,b,c:</p>
  
  <p><a href="https://i.stack.imgur.com/lJeS1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lJeS1.png" alt="Image"></a></p>
  
  <p>As you can see it doesn't do the combinations back to front such as </p>
  
  <pre><code>c,b,a
  c,a,b
  c,a
  ....
  </code></pre>
  
  <p>Here's the current code I have where I would like to implement this:</p>
  
  <pre><code>public void permutation(String str) {
  
    permutation("", str);
  }
  
  private void permutation(String prefix, String str) {
  
      int n = str.length();
      if (n == 0) myList.add(prefix);
      else {
          for (int i = 0; i &lt; n; i++)
  
              permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
  
      }
  }
  </code></pre>