title: Permutation of an ArrayList of numbers using recursion
body: <p>I am trying to learn recursion by creating a permutation of an ArrayList:</p>
  
  <pre><code> {1,2,3}
  </code></pre>
  
  <p>but the concept of recursive calls just keeps going over my head. I know how to do an iterative solution. but is there a systematic way to convert my iterative solution to recursive?</p>
  
  <pre><code>private static ArrayList&lt;ArrayList&lt;Integer&gt;&gt; permutate(ArrayList&lt;Integer&gt; list) {
      ArrayList&lt;ArrayList&lt;Integer&gt;&gt; result = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();
  
      result.add(new ArrayList&lt;Integer&gt;());
  
      for (int i = 0; i &lt; list.size(); i++) {
          ArrayList&lt;ArrayList&lt;Integer&gt;&gt; current = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();
  
          for (ArrayList&lt;Integer&gt; l : result) {
              for (int j = 0; j &lt; l.size()+1; j++) {
                  l.add(j, list.get(i));
  
                  ArrayList&lt;Integer&gt; temp = new ArrayList&lt;Integer&gt;(l);
                  current.add(temp);
  
                  l.remove(j);
              }
          }
  
          result = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;(current);
      }
  
      return result;
  
  }
  </code></pre>