title: ClassCastException: ArrayList cannot be cast to String
body: <p>I get this error:</p>
  
  <blockquote>
    <p>java.lang.ClassCastException: java.util.ArrayList cannot be cast to
    java.lang.String</p>
  </blockquote>
  
  <p>This is the code:</p>
  
  <pre><code>public static List&lt;String&gt;produit_cart(ArrayList l)
  {   
      List&lt;String&gt;re=new ArrayList();
      List&lt;String&gt;l4=new ArrayList();
  
      re=(List&lt;String&gt;) l.get(0);
  
      for(int i=1;i&lt;l.size();i++)
      {
          l4=new ArrayList();
  
          for(int j=0;j&lt;re.size();j++)
          {
              for(int k=0;k&lt;((ArrayList)l.get(i)).size();k++)
              {
                  l4.add(re.get(j) +
                          " " +
                          (String)((ArrayList)l.get(i)).get(k));
  
              }   
          }
  
          re=new ArrayList();
          for(int m=0;m&lt;l4.size();m++)
          {
              re.add(l4.get(m));
          }   
      }
  
      return re;
  }
  </code></pre>
  
  <p>The problem is in this line: </p>
  
  <pre><code>l4.add(re.get(j)+" "+(String)((ArrayList)l.get(i)).get(k));
  </code></pre>
  
  <p>I tried to rewrite it as:</p>
  
  <pre><code>l4.add(re.get(j)+" "+((ArrayList)l.get(i)).get(k));
  </code></pre>
  
  <p>but it didn't work. What should I do ?</p>