I encountered a problem when I tried to run the following code:
ArrayList paretoSet=new ArrayList(); // contains a collection of ArrayList
ArrayList<Integer> toPass=new ArrayList<Integer>();
int[] fParetoSet=new int[ParetoSet.size()];
int[] gParetoSet=new int[ParetoSet.size()];
for (int i=0;i<paretoSet.size();i++){
toPass.clear();
toPass.add((Integer)paretoSet.get(i));
int [] totake=calculate(toPass);
fParetoSet[i]=totake[0];
gParetoSet[i]=totake[1];
}
`
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 toPass.add((Integer)paretoSet.get(i));
as java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Integer
How should I fix this problem?
Thanks in advance
PareToSet
should start with a lower case letter; I thought you were calling a static method at first. – markspace Aug 12 '14 at 3:27ParetoSet
. I assume it'sArrayList
s, but show us to confirm. – Sotirios Delimanolis Aug 12 '14 at 3:30ArrayList<ArrayList<Integer>>
, correct? – Steve McKay Aug 12 '14 at 3:35