gishara gishara - 10 months ago 73
Java Question

Convert a double array to Double ArrayList

When I try to convert a double array to a Double arrayList I got the following error:

Exception in thread "main" java.lang.ClassCastException: [D cannot be cast to java.lang.Double

Below is my code.

double [] firstValueArray ;

ArrayList <Double> firstValueList = new ArrayList (Arrays.asList(firstValueArray));

I am comparing this list with another list and assign the result to another double variable.

Please let me know the reason for this error.


Alas, Arrays.asList(..) doesn't work with primitives. Apache commons-lang has

Double[] doubleArray = ArrayUtils.toObject(durationValueArray);
List<Double> list = Arrays.asList(doubleArray);