title: permutations of a list java
body: <p>I am trying to generate all possible permutations of a given list in a generic function. I think I have the function code correct. However, during testing time I keep getting compiler errors from my main program. Please help!</p>
  
  <pre><code>import java.util.*;
  
  class perms &lt;E&gt;{
  
    public List&lt;List&lt;E&gt;&gt; generatePerm(List&lt;E&gt; original) {
        if (original.size() == 0) { 
            List&lt;List&lt;E&gt;&gt; result = new ArrayList&lt;List&lt;E&gt;&gt;();
            result.add(new ArrayList&lt;E&gt;());
            return result;
        }
  
        E firstElement = original.remove(0);
        List&lt;List&lt;E&gt;&gt; returnValue = new ArrayList&lt;List&lt;E&gt;&gt;();
        List&lt;List&lt;E&gt;&gt; permutations = generatePerm(original);
  
        for (List&lt;E&gt; smallerPermutated : permutations) {
            for (int index=0; index &lt;= smallerPermutated.size(); index++) {
                List&lt;E&gt; temp = new ArrayList&lt;E&gt;(smallerPermutated);
                temp.add(index, firstElement);
                returnValue.add(temp);
            }
        }
  
        return returnValue;
    }
  
    public static void main(String[] params){
        List&lt;Integer&gt; p = new ArrayList&lt;Integer&gt; ();
        p.add(1);
        p.add(2);
  
        System.out.print(p.toString());
  
        List&lt;List&lt;Integer&gt;&gt; resultantList=generatePerm(p);
  
        System.out.print(resultantList.toString());
    }
  }
  </code></pre>
  
  <p>I keep generating the following error in my testing portion:</p>
  
  <pre><code>perms.java:33: generatePerm(java.util.List&lt;E&gt;) in perms&lt;E&gt; cannot be applied to (java.util.List&lt;java.lang.Integer&gt;)
  List&lt;List&lt;Integer&gt;&gt; resultantList=generatePerm(p);
  </code></pre>