title: List all permutations & combinations in Integer Arraylist recursively
body: <p>I have a method <code>perm1</code> that prints all permutations/combinations of characters in a string</p>
  
  <pre><code>// print permutation / combination of the characters of the string s (in order)
  public  static void perm1(String s) { perm1("", s); }
  private static void perm1(String prefix, String s) {
      int N = s.length();
      if (N == 0) System.out.println(prefix); 
      else {
          System.out.println(prefix);
          for (int i = 0; i &lt; N; i++)
             perm1(prefix + s.charAt(i), s.substring(0, i) + s.substring(i+1, N));
      }
  }
  </code></pre>
  
  <p><code>perm1</code> works OK and produces the desired output. </p>
  
  <p>I am trying to create a similar method <code>perm2</code> that works on an arraylist of Integers</p>
  
  <pre><code>public static void perm2(ArrayList&lt;Integer&gt; a) {
      ArrayList&lt;Integer&gt; sub = new ArrayList&lt;Integer&gt;(); 
      perm2(sub, a);
  }
  public static void perm2(ArrayList&lt;Integer&gt; sub, ArrayList&lt;Integer&gt; a){
      int L = a.size();
      if (L==0) System.out.println(sub);
      else {
          System.out.println(sub);
          for (int i = 0; i &lt; L; i++){
              sub.add(a.get(i));
              a.remove(i);
              perm2(sub, a);
              L = a.size(); // to avoid Index out of bounds exception
          }           
      }
  }
  </code></pre>
  
  <p>This does not generate all the permutations and combinations as I am hoping. Using an arraylist [1, 2, 3], it only prints the following:</p>
  
  <pre><code>[]
  [1]
  [1, 2]
  [1, 2, 3]
  </code></pre>
  
  <p>Can anyone please tell me how to modify perm2 so that it will print the other expected values like [2] [3] [2, 3] [3, 2] [2, 3, 1] [2, 1, 3] etc...</p>