title: How to fix: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Integer
body: <p>I encountered a problem when I tried to run the following code: </p>
  
  <pre><code>ArrayList paretoSet=new ArrayList();   // contains a collection of ArrayList
  ArrayList&lt;Integer&gt; toPass=new ArrayList&lt;Integer&gt;();
  int[] fParetoSet=new int[ParetoSet.size()];
  int[] gParetoSet=new int[ParetoSet.size()];
  
  for (int i=0;i&lt;paretoSet.size();i++){
          toPass.clear();
          toPass.add((Integer)paretoSet.get(i));
          int [] totake=calculate(toPass);
          fParetoSet[i]=totake[0];
          gParetoSet[i]=totake[1];       
      }
  </code></pre>
  
  <p>`
  where claculate(ArrayList x) is a method that takes an integer arraylist and returns an integer array. I can not make Paretoset an integer arraylist as it creates problem in other parts of my program. I encountered an exception in the line             <strong>toPass.add((Integer)paretoSet.get(i));</strong><br>
  as <em>java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Integer</em>
    How should I fix this problem?<br>
    Thanks in advance</p>