Java将ArrayList转换为int数组 [英] Java convert ArrayList to int array

查看:1771
本文介绍了Java将ArrayList转换为int数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的arraylist转换为一个double array []. 为什么我不能使用这种方法进行投射,这是怎么回事?

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);

    }

}

我收到此错误消息

String cannot be cast to java.lang.Double

如果我将fropm原始类型ArrayList更改为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(",")));

推荐答案

使用此:

array[x]=Double.parseDouble(list.get(x));

这篇关于Java将ArrayList转换为int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆