[Solved] Java 2D string or arraylist?


Option 1:

    List<String[]> dataSet = new ArrayList<String[]>();

    dataSet.add(new String[] { "abc", "def", "ghi" });
    dataSet.add(new String[] { "xyz" });
    dataSet.add(new String[] { "lmn", "opq", "rst", "uvw" });

Option 2:

If you know the number of rows in advance, you can also do this:

    int numRows = 3; //if you know the number of rows in advance
    String[][] dataSet2 = new String[numRows][]; 

    dataSet2[0] = new String[] { "abc", "def", "ghi" };
    dataSet2[1] = new String[] { "xyz" };
    dataSet2[2] = new String[] { "lmn", "opq", "rst", "uvw" };

0

solved Java 2D string or arraylist?