package com.golden.servlet.util;
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String str = "1,2;3,4,5;6,7,8;9";
for (double[] ds : parseDoubleArray(str)) {
System.out.println(Arrays.toString(ds));
}
}
public static double[][] parseDoubleArray(String arraystr){
double[][] ds = new double[arraystr.split(";").length][];
for (int i = 0; i < ds.length; i++) {
String temp = arraystr.split(";")[i];
String[] temp1 = temp.split(",");
double[] tempArray = new double[temp1.length];
for (int j = 0; j < tempArray.length; j++) {
tempArray[j] = Double.valueOf(temp1[j]);
}
ds[i] = tempArray;
}
return ds;
}
}
结果:
[1.0, 2.0]
[3.0, 4.0, 5.0]
[6.0, 7.0, 8.0]
[9.0]
public static void main(String[] args) {
String s = "1,2;3,4,5;6,7,8;9";
String[] ss = s.split(";");
String[] sss = null;
double[][] d = new double[4][3];
for (int i = 0; i < ss.length; i++) {
sss = ss[i].split(",");
for (int j = 0; j < sss.length; j++) {
d[i][j] = Double.parseDouble(sss[j]);
}
}
System.out.println(d);
}
纯手打,请给分
给100分 分太低了