Copying ArrayList data, not references


    Feb 09 2007 | 7:39 pm
    I hope that title makes some sort of sense...
    I have to preface this by mentioning that I'm not even certain I've found the bug in my class, but I *think* I've found it.
    I've got two Maps that will have different ways of using the contents of an single ArrayList. The ArrayList is all fine and happy as a value inside Map1. What I want to do is get the data from the ArrayList in Map1, move it over to Map2, and arrange it a little differently. I did a simple:
    newArrayList = Map1.get(keyToOldArrayList); Map2.put(newKey,newArrayList);
    as a way of moving the data over. However, when I alter Map2, oldArrayList in Map1 gets altered as well. This is no big surprise, but how do I avoid it? I tried:
    newArrayList.addAll(Map1.get(keyToOldArrayList);
    but that has the same result (or so it seems).
    BTW, if this is the way I'm supposed to copy the data, in order to make a copy I can manipulate without messing with Map1, then I've got another problem somewhere else and I'll leave everybody alone. I just can't see anywhere else that could be giving me this sort of trouble.
    J.