我需要解析一个字符串并将它们存储在一个二维双数组中。我的字符串是
-0.06409677515180673 0.12516724483856012 -0.06188844693840026 0.1542289929525214 -0.06603595481351604 0.07823062287735344 0.10161817634744892 $ -0.33597610014929263
double[][] A = -0.06409677515180673
0.12516724483856012
-0.06188844693840026
0.1542289929525214
-0.06603595481351604
0.07823062287735344
0.10161817634744892
double [][] B = -0.33597610014929263
它们都应该是列二维数组。
我尝试用 $ 拆分,但它不起作用。我试过的
String getpart = "my string";
double[][] A = null;
String[] parts = getpart.split("\\$");
String part1 = parts[0];
String part2 = parts[1];
/*checking for part 1*/
int i = 0;
StringTokenizer st= new StringTokenizer(part1," ");
String getdata = null;
while (st.hasMoreTokens()) {
int j=0;
getdata = st.nextToken();
A[i][j] = Double.parseDouble(getdata);
i++;
}
但显示空指针异常A[i][j] = Double.parseDouble(getdata);
有什么建议么?