请问问,怎么能用一维数组定义二维字符串数组吗?如何定义?谢谢各位教教我!

解决方案 »

  1.   

    public class Test1
    {
      static public void main( String args[] ) {
    String[] s1 = new String[]{"1","2"};
    String[] s2 = new String[]{"3","4"};
    String[][] s3 = new String[][]{s1,s2};
    for(int i=0;i<s1.length;i++){
    for(int c=0;c<s2.length;c++){
    System.out.println(s3[i][c]);
    }
    }
      }
    }
      

  2.   

    基本类型的一维数组是不能定义二维字符串数组的!你可以用arraylist来存放两个一维的字符串数组
      

  3.   

    建议楼主学一下java 的collection集合,collection类中,有很多种类型很方便地实现你的功能,collection集合可是JAVA特有好的好东西啊~~~
      

  4.   

    public class T
    {
    public static void main(String[] args)
    {
    // 定义二维字符串数组
    String[][] str2Arr1 = new String[][]{{"Hello!","susan14"},
    {"Happy","Yzl","Very"},
    {"Two","One"}};

    String[][] str2Arr2 = new String[][]{{"One!","Two"},
    {"Three","Yzl","Four"},
    {"Two","One"}};

    //定义一维数组(它包含二维字符串)
    Object[] obj = new Object[]{str2Arr1,str2Arr2};

    // 输出
    for(int i = 0; i < obj.length; i ++)
    {
    String[][] tmp = (String[][])obj[i];
    for (int j = 0; j < tmp.length; j ++)
    for (int k = 0; k < tmp[j].length; k ++)
    System.out.print(tmp[j][k]);
    System.out.println();
    }
    }
    }