I
Ike
I have a HashMap which has Strings as Keys, and stores ArrayList Objects. I
have a method then that loooks into the HashMap, and, if the Key for the
word is found, returns the ArrayList, and if not, creates a new Arraylist
and both adds it to the HashMap as well as returns the ArrayList.
However. in the step where if the key is found in the HashMap, its is not
copying the ArrayList object stored in the HashMap to ArrayList I want to
return. Can anyone tell me why? Code is given below:
private ArrayList getElemementAncestorsListNoSemantics(String s){
ArrayList retlist=new ArrayList();
if(hmap3.containsKey(s)){
retlist.addAll((ArrayList)hmap3.get(s));// <---PROBLEM *
}else{
//get the arraylist for the String s, and put it in both the
retlist to return and the HashMap hmap3
//for later lookup
retlist.addAll(makemynewarraylist(s));
hmap3.put(s,retlist);
}
return retlist;
}
* I am certain that the ArrayList for the given key, s, exists at this
point. It is just not being copied over into the ArrayList retlist.
//-Ike
have a method then that loooks into the HashMap, and, if the Key for the
word is found, returns the ArrayList, and if not, creates a new Arraylist
and both adds it to the HashMap as well as returns the ArrayList.
However. in the step where if the key is found in the HashMap, its is not
copying the ArrayList object stored in the HashMap to ArrayList I want to
return. Can anyone tell me why? Code is given below:
private ArrayList getElemementAncestorsListNoSemantics(String s){
ArrayList retlist=new ArrayList();
if(hmap3.containsKey(s)){
retlist.addAll((ArrayList)hmap3.get(s));// <---PROBLEM *
}else{
//get the arraylist for the String s, and put it in both the
retlist to return and the HashMap hmap3
//for later lookup
retlist.addAll(makemynewarraylist(s));
hmap3.put(s,retlist);
}
return retlist;
}
* I am certain that the ArrayList for the given key, s, exists at this
point. It is just not being copied over into the ArrayList retlist.
//-Ike