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 006247241 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 cellValues[]).
Map<String, List<String>> map = new HashMap<String, List<String>>();
List<String> list = new ArrayList<String>();
String key="#";
for(int k=0;k<cellValues.length;k++){
if(cellValues[k]!=null){
if(cellValues[k].length()<=9 && cellValues[k].length()>0 ){
map.put(key,list);
//System.out.println("MAP:"+map);
key=cellValues[k];
}else{
list.add(cellValues[k]);
}
}
}
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
Key = 006247241 Values = [#, 0590040100000124,0590020100000125,0590020450000124, 0590040100000129
Key = 006247242 Values = [#, 0590040100000124,0590020100000125,0590020450000124, 0590040100000129