title: error: incompatible types: List<Integer> cannot be converted to ArrayList<Integer>
body: <p>I have found a few questions similar to the problem I am facing, but I couldn't find solution.
  Example: <a href="https://stackoverflow.com/questions/24796273/incompatible-types-list-of-list-and-arraylist-of-arraylist">Incompatible types List of List and ArrayList of ArrayList</a>, <a href="https://stackoverflow.com/questions/45319323/not-able-to-understand-how-to-define-a-list-of-list-in-java?noredirect=1&amp;lq=1">Not able to understand how to define a List of List in java</a> </p>
  
  <p>The program should return list of lists. So, I declared a list of lists and then trying to add arraylists to it. </p>
  
  <pre><code>allsubsets = new ArrayList&lt;List&lt;Integer&gt;&gt;();
  </code></pre>
  
  <p>But, when I am trying to access each arraylist item from the list of lists as below, I get the error: <code>incompatible types: List&lt;Integer&gt; cannot be converted to ArrayList&lt;Integer&gt;</code> </p>
  
  <pre><code>for(ArrayList&lt;Integer&gt; subset:allsubsets)
  </code></pre>
  
  <p>When I try to convert the line to <code>for(List&lt;Integer&gt; subset:allsubsets)</code>, it throws error that add, addAll don't exist for List type, which makes sense. Please help me understand how to access elements of list of lists in this case.</p>
  
  <pre><code>public List&lt;List&lt;Integer&gt;&gt; subsets(int[] nums) {
      List&lt;Integer&gt; arrayList = new ArrayList&lt;Integer&gt;();
      for(int i:nums) {
          arrayList.add(i);
      }
      return subsets(arrayList,nums.length);
  }
  
  public List&lt;List&lt;Integer&gt;&gt; subsets(List&lt;Integer&gt; arrayList, int index) {
      List&lt;List&lt;Integer&gt;&gt; allsubsets;
      if(index == -1) {
           allsubsets = new ArrayList&lt;List&lt;Integer&gt;&gt;();
           allsubsets.add(new ArrayList&lt;Integer&gt;());
      }
      else {
          allsubsets = subsets(arrayList, index-1);
          int item = arrayList.get(index);
          List&lt;List&lt;Integer&gt;&gt; moresubsets =  new ArrayList&lt;List&lt;Integer&gt;&gt;();
          for(ArrayList&lt;Integer&gt; subset:allsubsets) { 
          //The line above throws error as I created list of lists
  
              List&lt;Integer&gt; newsubset = new ArrayList&lt;Integer&gt;(); //create new subset
              newsubset.addAll(subset); // add all old items
              newsubset.add(item); // add new item
              moresubsets.add(newsubset); //add subset to moresubsets
          }
          allsubsets.add(moresubsets); // add to actual one
      }
    return allsubsets;
  }
  </code></pre>
  
  <p>Note: If I change the return type to arraylist of arraylists, it works for me. But, I want to make it work for the list of lists</p>