Convert String[] with text to double[]

后端 未结 5 1099
旧巷少年郎
旧巷少年郎 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
    2021-01-29 15:44

    This will do the work.

    double[] doubles = new double[array1.length];
    for(int i=0; i

    Thanks SmartLemon for the edit, you could do this too instead of using a String[]:

    double[] doubles = new double[list1.size()];
    for(int i=0; i

    EDIT: So yes, you need a delimiter:

    double[] doubles = new double[array1.length*2]; //multiply by 2 because you really have 8 numbers not 4
    String [] array2 = null;
    
    for(String string: array1) { 
        array2 = string.split(",");
        for(int i=0; i

    this should do the work for sure.

提交回复
热议问题