title: how to declare ArrayList of ArrayList in java
body: <p>I want to declare an <code>ArrayList</code> within another <code>ArrayList</code>.</p>
  
  <p>I declared <code>ArrayList</code> of <code>ArrayList</code> and added the elements in the following manner successfully but at the time of retrieval its showing class cast exception.</p>
  
  <pre><code>List&lt;List&lt;UnderDefinedFunction&gt; parentAL=new ArrayList&lt;List&lt;UserDefinedFunction&gt;&gt;();
  List&lt;UserdefinedFunction&gt; childAL=new ArrayList&lt;UserDefined&gt;();
  
  childAL.add(userdefinedfunction);
  ...............
  ..............
  parentAL.add(childAL);
  </code></pre>
  
  <p>At the time of retrieval it is showing class cast exception.</p>
  
  <pre><code>for(int i=0;i&lt;parentAL.size();i++){
      List&lt;UserDefinedFunction&gt; al=parentAL.get(i);
  }
  </code></pre>
  
  <p>I tried with following code also:</p>
  
  <pre><code>ArrayList&lt;ArrayList&lt;UserDefinedfunction&gt; al=new ArrayList&lt;ArrayList&lt;UserDefinedFunction&gt;&gt;();
  </code></pre>
  
  <p>but I am getting same problem.</p>
  
  <p>Why is it showing any error any mistake is done any idea ???</p>