title: Generating all combinations of a String with multithreading
body: <p>I need to generate all possible combinations of a string, using multithreading to split the work equally among N threads. So the string <code>cat</code> would output:</p>
  
  <pre><code>c, a, t, ca, ct, ac, at, ta, tc, cat, cta, tac, tca, act, atc
  </code></pre>
  
  <p>Each thread contains a <code>startIndex</code> and <code>endIndex</code> and does a different processing of the string. Right now I can generate all permutations of a string but I am absolutely stumped on what I need to do to modify it to get all combinations. Any help would be greatly appreciated.</p>
  
  <p>This is what I have right now:</p>
  
  <pre><code>public void run() {
      for(int i = startIndex; (i &lt; endIndex); i++) {
          swap(word, 0, i); // Swap character to zero location.
          permuteAndCheck(word, 1); // Recursively check permutations
          swap(word, 0, i); // Undo swap
      }
  }
  
  private void permuteAndCheck(char[] word, int start) {
      if (start &lt; word.length) {
          // Not yet at the deepest recursion level to compare permutations.
          for(int i = start; (i &lt; word.length); i++) {
              swap(word, start, i);
              permuteAndCheck(word, start + 1);
              swap(word, start, i); // Restore entry back from previous swap
          }
          return;
      }
  
      System.out.print(word + ", ");
  }
  
  private static final void swap(char[] word, int index1, int index2) {
      char temp  = word[index1];
      word[index1] = word[index2];
      word[index2] = temp;
  }
  </code></pre>