Convert String[] with text to double[]

后端 未结 5 1095
旧巷少年郎
旧巷少年郎 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条回答
  •  遇见更好的自我
    2021-01-29 15:31

    I would do this:

    • make array
    • convert to string

    then this code

    for (String s: list1) {
        boolean obtained = false;
        double tempD;
    
        try {
            tempD = Double.parseDouble(s); 
            obtained = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    
        if (obtained) {
            list2.add(tempD);
        }
    }
    

提交回复
热议问题