Java:how to group similar strings (items) to respective array (group)?
<p>I have the following string <code>"0#Aitem, 0#Aitem2, 0#Aitem3, 1#Bitem, 1#Bitem2, 2#Citem, Nitem, Nitem2".</code></p>

<p>the 0# shows group number. so <code>Aitem, Aitem2, Aitem3</code> will belong to group <code>0</code>. <code>Bitem, Bitem2</code> in group <code>1</code>. <code>Citem</code> in group <code>2</code>. If there is no group number, they will all be place in separate group. So <code>Nitem, Nitem2</code> will be placed in group <code>3</code>.</p>

<p>I would like to create an array for each group, and place the "items" in respective group(array). So I would end up with something like</p>

<pre><code>[array("Aitem,Aitem2,Aitem3"), array("Bitem, Bitem2"), array("Citem"), array("Nitem, Nitem2")]
</code></pre>

<p>I am guessing I need an arrayList to hold all the groups (arrays) which respectively has appropriate elements (items).</p>

<p>This is what I started with but I don't know if this is the best approach. The string is dynamic, so there can be any number of groups and has to follow the criteria above.</p>

<pre><code>String[] x = Pattern.compile(",").split("0#item, 0#item2, 0#item3, 1#item, 1#item2, 2#item, item");
   for (int ii=0; ii&lt;x.length; ii++) {
       System.out.println(i + " \"" + x[ii] + "\"");
   }
</code></pre>
