title: Java generate all possible permutations of a String
body: <p>I know this question has been asked many times, but I'm looking for a very fast algorithm to generate all permutations of Strings of length 8. I am trying to generate a String of length 8, where each character in the String can be any of the characters 0-9 or a-z (36 total options). Currently, this is the code I have to do it:</p>
  
  <pre><code>for(idx[2] = 0; idx[2] &lt; ch1.length; idx[2]++)
  for(idx[3] = 0; idx[3] &lt; ch1.length; idx[3]++)
      for(idx[4] = 0; idx[4] &lt; ch1.length; idx[4]++)
          for(idx[5] = 0; idx[5] &lt; ch1.length; idx[5]++)
              for(idx[6] = 0; idx[6] &lt; ch1.length; idx[6]++)
                  for(idx[7] = 0; idx[7] &lt; ch1.length; idx[7]++)
                      for(idx[8] = 0; idx[8] &lt; ch1.length; idx[8]++)
                          for(idx[9] = 0; idx[9] &lt; ch1.length; idx[9]++) 
                              String name = String.format("%c%c%c%c%c%c%c%c%c%c",ch1[idx[0]],ch2[idx[1]],ch3[idx[2]],ch4[idx[3]],ch5[idx[4]],ch6[idx[5]],ch7[idx[6]],ch8[idx[7]],ch9[idx[8]],ch10[idx[9]]);
  </code></pre>
  
  <p>As you can see, this code is not pretty by any means. Also, this code can generate 280 thousand Strings per second. I'm looking for an algorithm to do it even faster than that. </p>
  
  <p>I've tried a recursive approach, but that seems to run slower than this approach does. Suggestions?</p>