WHY
Friends in the group to ask for a question, the problem prototype is this:
String str = "{{10.14, 11.24, 44.55, 41.01},{12.10, 14.21, 52.14, 50.44},{14.44, 16.12, 45.42, 47.55}}";
Convert to double[][]{
{10.14, 11.24, 44.55, 41.01},
{12.10, 14.21, 52.14, 50.44},
{14.44, 16.12, 45.42, 47.55}
}
A two-dimensional array that converts a string that can be converted into a double.
How
At first glance, it feels so simple, it's implemented, and it's customary to paste the code first:
String str = "{{10.14, 11.24, 44.55, 41.01},{12.10, 14.21, 52.14, 50.44},{14.44, 16.12, 45.42, 47.55}}";
str = str.replace ("{", "["). Replace ("}", "]");
string[][] arr = json.parseobject (str, string[][].class);
Double[][] ds = new Double[arr.length][arr[0].length];
for (int j=0;j<arr.length;j++) {for
(int i=0;i<arr[0].length;i++) {
Ds[j][i] = double.valueof (arr[j][ I]);
}
Here are a few points to be aware of
1. Replace the curly braces with the brackets first,
2. Using JSON transformation, first turn into a string two-dimensional array
3. Then the value in the array is converted to a double
4. The JSON package I use is Fastjson.
Import Com.alibaba.fastjson.JSON;
The above is the small series for everyone to bring Java String into a double two-dimensional array of methods all the content, I hope that we support the cloud Habitat Community ~