Strin类-split方法

//分解字符串
public class Quit {
	public static void main(String[] args){
		double[][] d;
		String s="1,2;3,4,5;6,7,8,9";
		String[] sFirst=s.split(";");//以";"为分隔符
		d= new double[sFirst.length][];
		
		for(int i=0;i<sFirst.length;i++){
			String[] sSecond =sFirst[i].split(",");
			d[i]=new double[sSecond.length];
			for(int j=0;j<sSecond.length;j++){
				//d[i]=new double[sSecond.length];
				//字符串转成double类型的数字
			   d[i][j]=Double.parseDouble(sSecond[j]);
			}
		}
		
		for(int i=0;i<d.length;i++){
			for(int j=0;j<d[i].length;j++){
				System.out.print(d[i][j]+" ");
			}
			System.out.println();
		}
	}
}

猜你喜欢

转载自blog.csdn.net/hpuxiaofang/article/details/53102625