title: Calculate all permutations of a collection in parallel
body: <p><BR>
  I need to calculate all permutations of a collection and i have a code for that but the problem is that it is linear and takes a lot of time.</p>
  
  <pre><code>public static &lt;E&gt; Set&lt;Set&lt;E&gt;&gt; getAllCombinations(Collection&lt;E&gt; inputSet) {
      List&lt;E&gt; input = new ArrayList&lt;&gt;(inputSet);
      Set&lt;Set&lt;E&gt;&gt; ret = new HashSet&lt;&gt;();
      int len = inputSet.size();
      // run over all numbers between 1 and 2^length (one number per subset). each bit represents an object
      // include the object in the set if the corresponding bit is 1
      for (int i = (1 &lt;&lt; len) - 1; i &gt; 0; i--) {
          Set&lt;E&gt; comb = new HashSet&lt;&gt;();
          for (int j = 0; j &lt; len; j++) {
              if ((i &amp; 1 &lt;&lt; j) != 0) {
                  comb.add(input.get(j));
              }
          }
          ret.add(comb);
      }
      return ret;
  }
  </code></pre>
  
  <p>I am trying to make the computation run in parallel.</p>
  
  <p>I though of the option to writing the logic using recursion and then parallel execute the recursion call but i am not exactly sure how to do that.</p>
  
  <p>Would appreciate any help.</p>