I want to convert my arraylist to a double array[]. Why can't I cast with this method, what is wrong?
public static void convert(ArrayList list, double array[]) {
array = new double [list.size()];
for (int x = 0; x < list.size(); x++) {
array[x]=(double) list.get(x);
}
}
I get this error message
String cannot be cast to java.lang.Double
I have this peace of code that does not work if I change fropm raw type ArrayList to Double, maybe suggestions to change this code?
getTest().addAll(Arrays.asList(line.split(",")));
Exception message says it - your ArrayList contains String values. You should use generics as
ArrayList<String>
to prevent this runtime failures