title: How to put Multiple ArrayLists inside an ArrayList Java
body: <p>I am trying to create a parent ArrayList which contains a sub ArrayList for each of its index(s).  My code involves filling the sub lists by using Scanner Input.  See input example below.</p>
  
  <p>Input Description: The first integer inputed (<code>int T</code>) tells us how many sub ArrayLists we are going to make,this could also be seen as the size of the parent ArrayList or as how many lines of input are going to follow. All lines after this point will be the integers we want to store within each sub arraylist.</p>
  
  <p>Example Input                          </p>
  
  <pre><code>2  
  5 4 2 9  
  1 3 3 7  
  </code></pre>
  
  <p>Expected Output</p>
  
  <pre><code>SubString 0 contains 5 4 2 9
  SubString 1 contains 1 3 3 7
  </code></pre>
  
  <p>Problem Description: I get an error on the following line <code>parentList.add(i, subList.add(q.nextInt()));</code>. I believe I am not following syntax. I have tried using .addAll but that doesn't work either. Can anyone tell me what I am doing wrong? Thanks for help in advance. </p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Serials {
  
  
      public static void main(String[] args) {
  
          int T = 0; //First Integer to be inputed 
          //tells me how many sub ArrayLists I will have
  
          List&lt;List&lt;Integer&gt;&gt; parentList =new ArrayList();  //parentList
          List&lt;Integer&gt; subList = new ArrayList();          //subList
  
          Scanner q=new Scanner(System.in);
          System.out.println("How many substrings do we need");
          T = q.nextInt(); //Scanning in T Value
  
          for(int i=0; i&lt;T; i++) {
  
      subList = new ArrayList&lt;Integer&gt;();
      subList.add(q.nextInt());
      parentList.add(i, subList);  
  
  
      }
  
  
      System.out.println( "SubString 0 contains" + parentList.get(0));
      System.out.println( "SubString 1 contains" + parentList.get(1));
  
  
      }
  }
  </code></pre>