public class splitStringToDouble{
public static void main(String[] args){
String s="1,2,3;4,5,6,8;390;39";
splitStr(s);
}
static void splitStr(String str){
String[] splStr=str.split(";");
String[][] splStrAg=new String[splStr.length][];
double[][] d=new double[splStr.length][];
for(int i=0;i<splStr.length;i++){
splStrAg[i]=splStr[i].split(",");
}
for(int i=0;i<splStr.length;i++)
for(int j=0;j<splStrAg[i].length;j++){
System.out.print(splStrAg[i][j]+" ");
if(splStrAg[i][j]==null){
System.out.println("null");
}
try{
d[i][j]=Double.parseDouble(splStrAg[i][j]);
}catch (NullPointerException e){
System.out.println("a String is null");
}
}
}
}
你都是二維數組,你初始化了第一維