java- how to logically process n-levels of for loops where n is a variable
<p>In a java program, I am getting some data with each value being assigned a name-
Each data item has a 'level' which is a numeric value.</p>

<p>For level 1, there are 'n' number of values--
the data items have names </p>

<pre><code> 1-1, 1-2, 1-3.....1-n.
</code></pre>

<p>Now, level 2 items have names which are derived from level 1's data items.</p>

<p>So there can be 'm' values of level 2, corresponding to each level 1 item. In the name of each data item, each named section corresponding to a level, is separated from other section of name with a '~'.</p>

<p>For eg, </p>

<pre><code>    1-1~2-1, 1-1~2-2, 1-1~2-3......1-1~2-m ---&gt;level2 corresp. to level 1 item "1-1"
    1-2~2-1, 1-2~2-2, 1-2~2-3, ....1-2~2-m---&gt;level2 corresp. to level 1 item "1-2"
</code></pre>

<p>Now, I want to create a function where a parameter is number of levels, and I want to programmatically access all items of that level.</p>

<p>For eg, I can create a for loop within another for loop, to access items of level 2.</p>

<p>But how do I do this for level=x, where x is a variable?</p>
