将双数组转换为双数组列表

问题描述:

当我尝试将双数组转换为双数组列表时,出现以下错误:

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

线程main"中的异常 java.lang.ClassCastException: [D 不能转换为 java.lang.Double

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

下面是我的代码.

double [] firstValueArray ;

ArrayList 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.

唉,Arrays.asList(..) 不适用于原语.Apache commons-lang 有

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

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