我需要在android中将字符串数组转换为double数组。但我的应用程序没有在我的设备上执行。它显示不幸停止了。以下是我的代码:
String dataa="0.121 0.547 0.875 0.245";
String delimiter = " ";
String spectrainstring[] = dataa.split(delimiter);
int size = spectrainstring.length;
double[] spectraldata={0.0};
for(int i=0;i<size;i++)
{
spectraldata[i]=Double.parseDouble(spectrainstring[i].toString());
}
答案 0 :(得分:1)
String dataa = "0.121 0.547 0.875 0.245";
String delimiter = " ";
String spectrainstring[] = dataa.split(delimiter);
int size = spectrainstring.length;
double[] spectraldata = new double[size];
for (int i = 0; i < size; i++) {
spectraldata[i] = Double.parseDouble(spectrainstring[i].toString());
System.out.println(spectraldata[i]);
}