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.
No, you cannot store doubles in ArrayList<Integer> without loss of precision. You can, however, store them in ArrayList<Double> .
To collect double values in an array list, you use an ArrayList<Double>. The array algorithms can be converted to array lists simply by using the array list methods instead of the array syntax.
Alas, Arrays.asList(..)
doesn't work with primitives. Apache commons-lang has
Double[] doubleArray = ArrayUtils.toObject(durationValueArray); List<Double> list = Arrays.asList(doubleArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With