* 把字符串分解成一个double类型的二维数组;
* s ="1,2;3,4,5;6,7,8";
* arr[0][1]=1.0 arr[1][1]=2.0
* arr[1][0]=3.0 arr[1][1]=4.0 arr[1][2]=5.0
* arr[2][0]=6.0 arr[2][1]=7.0 arr[2][2]=8.0
* @author Administrator
*
*/
public class StringTest {
public static void main(String[] args)
{
String s ="1,2;3,4,5;6,7,8";
String[] s1 = s.split(";");
Double[][] arr = new Double[s1.length][];
for(int x=0;x<s1.length;x++)
{
//System.out.println(s1[x]);
String[] s2 = s1[x].split(",");
arr[x] = new Double[s2.length];
for(int y=0;y<s2.length;y++)
{
System.out.println(s2[y]);
arr[x][y] = Double.parseDouble(s2[y]);
}
}
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr[i].length;j++)
{
System.out.print(+arr[i][j]+" ");
}
System.out.println();
}
}
} |
|