- *将字符串存储到二维的double数组中"1,2;3,4,5;6,7,8,9"
- a,用分号把字符串切成字符串数组,遍历这个字符串数组
- b,把每一个字符串元素再用,切
- c,再遍历新切完这个数组
- d,把这些单独元素通过数字字符串转成double数,存在double数组里
- */
- public class Test3 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String str = "1,2;3,4,5;6,7,8,9";
- String []arr = str.split(";");
- String[][] arr2 = new String[arr.length][];
- for (int i = 0; i < arr.length; i++) {
- arr2[i] = arr[i].split(",");
- }
-
- /* for (int i = 0; i < arr2.length; i++) {
- for (int j = 0; j < arr2[i].length; j++) {
- System.out.print(arr2[i][j]+ " ");
- }
- System.out.println();
- }*/
-
- double [][]arr3 = new double[arr.length][];
- for (int i = 0; i < arr.length; i++) {
- for (int j = 0; j < arr2[i].length; j++) {
- arr3[i][j] = Double.parseDouble(arr2[i][j]);
- }
- }
- }
- }
复制代码 |