title: Adding new list dynamically to Map
body: <p>I have an array like this 
   006247241  0590040100000124        0590020100000125        0590020450000124    006247242   0590040100000129 ...Now if the length of any value in the array is between 1 to 9 it become a key and the rest following it immediately become Values for which i use a Map. So in the above case <strong>006247241</strong>  becomes a key and 0590040100000124     0590020100000125        0590020450000124 become values for that key and so on. My code is like this(All the above values are in an array <strong>cellValues[]</strong>).</p>
  
  <pre><code>Map&lt;String, List&lt;String&gt;&gt; map = new HashMap&lt;String, List&lt;String&gt;&gt;();
              List&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
              String key="#";
  
              for(int k=0;k&lt;cellValues.length;k++){
                  if(cellValues[k]!=null){
                      if(cellValues[k].length()&lt;=9 &amp;&amp; cellValues[k].length()&gt;0 ){
                          map.put(key,list);
                          //System.out.println("MAP:"+map);
                          key=cellValues[k];
                      }else{
                          list.add(cellValues[k]);
                      }
                  }
              }
  </code></pre>
  
  <p>The problem i face here is how to add new list for each new key.The above code will just append all the values to each key in the array and the output would be like this         </p>
  
  <p>Key = 006247241 Values = [#, 0590040100000124,0590020100000125,0590020450000124, 0590040100000129</p>
  
  <p>Key = 006247242 Values = [#, 0590040100000124,0590020100000125,0590020450000124, 0590040100000129</p>