Does this line:
List params = (List) hashMap.get(key);
create a new list, or just appends it to the list?
Here is how I use the code:
ParameterCache cache = ParameterCache.getInstance();
HashMap hashMap = cache.getAllParameters(ParameterCodeConstants.PARAMETER_DORF_REGION, false);
ArrayList regionIdList=new ArrayList();
Set keys = hashMap.keySet();
Iterator it = keys.iterator();
while (it.hasNext()) {
BigDecimal key = (BigDecimal) it.next();
List params = (List) hashMap.get(key);
if (params != null && params.size() > 0) {
ParameterDTO paramDTO = (ParameterDTO) params.get(0);
String textValue = paramDTO.getParameterTextValue();
if(textValue.equals(region_id)){
regionIdList.add(paramDTO.getRegion());
}
}
}
None of this – only an assignment is taking place here. The value associated with
keyin this map is supposed to be a reference to an existingListobject (ornull), and this is returned byget. This reference is then assigned toparams.Since the local variable
paramsdid not exist prior to this declaration, there is no list to append anything to anyway.