Java, how to adjust second dimension of 2 dimensional array?
<p>In my application I need to have a 2 dimensional array. If I define it fix it works fine, like this:</p>

<pre><code>static final String arrGroupelements[] = {"India", "Australia", "England", "South Africa"};
    static final String arrChildelements[][] = { {"Sachin Tendulkar", "Raina", "Dhoni", "Yuvi" },
                                                 {"Ponting", "Adam Gilchrist", "Michael Clarke"},
                                                 {"Andrew Strauss", "kevin Peterson", "Nasser Hussain"},
                                                 {"Graeme Smith", "AB de villiers", "Jacques Kallis"} };
</code></pre>

<p>However, in my code I have two lists. the first is list of recipe name that i can get it.</p>

<pre><code>LinkedList&lt;String&gt; recipeList = dbShoppingHandler.getAllRecipeNames();
        String arrGroupelements[] = new String[recipeList.size()];
        for(int i=0; i&lt;recipeList.size(); i++) {
            arrGroupelements[i] = recipeList.get(i);
        }
</code></pre>

<p>My second list is list of ingredients. In order to get list of ingredients i need to set recipe name and then i can get the list. However, i don't know how put this list as second dimension. my code is like this:</p>

<pre><code>String arrChildelements[][] = new String[recipeList.size()][20];
        for(int i=0; i&lt;recipeList.size(); i++) {
            LinkedList&lt;String&gt; ingredient = dbShoppingHandler.getIngredientsOfRecipeName(recipeList.get(i));
            for(int j=0; j&lt;ingredient.size(); j++) {
                arrChildelements[i][j] = ingredient.get(j);
            }
        }
</code></pre>

<p>Bad thing is, i need to set a number (in my case 20) for second dimension. If i do like this for lists that have 5 items i will have 15 " " elements and those have more than 20 items the code ignore them.</p>

<p>First dimension is fix but i need to adjust second dimension based on number of ingredients.</p>

<p>any suggestion are appreciated. thanks.</p>
