java 对象数组怎么转换double数组?

2024-11-27 04:35:05
推荐回答(4个)
回答1:

import java.util.*;
public class Test {
public static void main(String[] args) {
List Num_num = new ArrayList();
List Num = new ArrayList();
String Str1 = "12";
String Str2 = "34";
Num.add(Str1);
Num.add(Str2);
for(int i = 0; i < Num.size(); i++){
Num_num.add(Double.parseDouble(Num.get(i)));
}
for(int i = 0; i < Num_num.size(); i++){
System.out.println(Num_num.get(i));
}
}
}

回答2:

你搞错了吧,ArrayList不是数组,而是集合,数组声明是这样的
String[] Num=.....
集合是不同数组的,两者是不同类型。集合可装不同对象,而数组只能装某种类型的

Num_num.add(Double.parseDouble(Num.get(Temp_i).toString());中
的Temp_i你并没有定义

回答3:

class StringArrayToDoubleArray{

public static void main(String args[]){

String s[] = new String[]{"11","22","33"};
Double d[] = new Double[3];

for(int i=0;i d[i] = Double.parseDouble(s[i]);
}

for(int j=0;j System.out.println(d[i]);
}

}

}

回答4:

//试试ArrayList的toArray()方法
import java.util.ArrayList;
public class Demo {
public static void main (String[] args)
{
//ArrayList Num_num = new double();
ArrayList Num = new ArrayList();
String Str1 = "12";
String Str2 = "34";
Num.add(Str1);
Num.add(Str2);
Object[] Num_num=new Object[2];
Num_num=Num.toArray();
//Num_num.add(Double.parseDouble(Num.get(Temp_i).toString());
for (int i = 0; i<2; i++)
{
System.out.println (Num_num[i]);
}
}
}