Convert String[] with text to double[]

后端 未结 5 1097
旧巷少年郎
旧巷少年郎 2021-01-29 15:02

I have an Arraylist that I want to convert to a double[] array. I first convert the Arraylist to a String []. I then try to convert the String[] to a double[] but fail in the p

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-29 15:50

    Use this

     String[] str1 = new String[list1.size()];
     str1 = list1.toArray(str1);
     double[] doubleArray = new double[str1.length]
     int i=0;
     for(String s:str1){
        doubleArray[i] = Double.valueOf(s.trim());
        i++;
     }
    

提交回复
热议问题