Stroring into 2d array
string b= acd:tyt:rt;
string a[][]=null;
for(int i=0;i<n;i++){
a[i]=b.split(":");
}
i want to store in 2d array rowwise? any solutions, above code says null ptr exception.>
string b= acd:tyt:rt;
string a[][]=null;
for(int i=0;i<n;i++){
a[i]=b.split(":");
}
i want to store in 2d array rowwise? any solutions, above code says null ptr exception.>
Although it doesn't make a lot of sense, this will compile:int n = 10;
String b= "acd:tyt:rt";
String[][] a= new String[n][];
for(int i = 0; i < n; i++){
a[i] = b.split(":");
}
String.split(String) does return an array of Strings, so this code will compile; now what's your problem? This code is different than the OP and shouldn't give you any exceptions. The result of this code, viewed as a grid should be
[["acd"]["tyt"]["rt"]
["acd"]["tyt"]["rt"]
["acd"]["tyt"]["rt"]
["acd"]["tyt"]["rt"]
["acd"]["tyt"]["rt"]
["acd"]["tyt"]["rt"]
["acd"]["tyt"]["rt"]
["acd"]["tyt"]["rt"]
["acd"]["tyt"]["rt"]
["acd"]["tyt"]["rt"]]
What do you want to happen?