Turn string values into 2d array of type double

前端 未结 5 938
失恋的感觉
失恋的感觉 2021-01-20 00:01

I have a string:

String stringProfile = \"0,4.28 10,4.93 20,3.75\";

I am trying to turn it into an array like as follows:

d         


        
5条回答
  •  猫巷女王i
    2021-01-20 00:41

    Assuming that your string strictly follows the given sample pattern, you can make use of the following code:

        String stringProfile = "0,4.28 10,4.93 20,3.75";
        stringProfile = stringProfile.replace(' ', ',');
        String [] strArry = stringProfile.split(",");
        double [][] doubleArray = new double [strArry.length/2][2];
        for(int i=0, j=0; i

提交回复
热议问题