title: Generating all possible permutations of a list recursively
body: <p>I'm trying to recursively generate all items in a list recursively. I've seen a few solutions to similar questions to this, but I haven't been able to get my code to work. Could someone point out how I can fix my code?</p>
  <p>This is open to all S/O'ers, not just Java people.</p>
  <p>(Also I should note that it crashes with a SO exception).</p>
  <p>Sample input:</p>
  <pre><code>[1, 2, 3]
  </code></pre>
  <p>Output:</p>
  <pre><code>[1, 2, 3]
  [1, 3, 2]
  [2, 1, 3]
  [2, 3, 1]
  [3, 1, 2]
  [3, 2, 1]
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>//allPossibleItems is an AL of all items 
  
  //this is called with generatePerm(null, new ArrayList&lt;Item&gt;);
  
  private void generatePerm(Item i, ArrayList&lt;Item&gt; a) {
      if (i != null) { a.add(i); }
      if (a.size() == DESIRED_SIZE) {
          permutations.add(a);
          return;
      }
      for (int j = 0; j &lt; allPossibleItems.size(); j++) {
          if (allPossibleItems.get(j) != i)
              generatePerm(allPossibleItems.get(j), a);
      }
  }
  </code></pre>