java - Collections.copy(dest, src) still Referencing Source Collection -


i have searched forum handling deep-copying of collections in hands, collections.copy(dest, src) isn't working expected. did miss something?

list<column> mergedstudies = new arraylist<column>(arrays.aslist(new column[studycolumns.size()]));     collections.copy(mergedstudies, studycolumns);      (iterator itrstudyreccolumns = mergedstudies.iterator(); itrstudyreccolumns.hasnext();) {         column studyreccol = (column) itrstudyreccolumns.next();         (iterator itrstudyvalcolumns = studyvaluecolumns.iterator(); itrstudyvalcolumns.hasnext();) {             column studyvalcol = (column) itrstudyvalcolumns.next();             if (studyreccol.getcolumnname().equals(studyvalcol.getcolumnname())) {                 // note: method dereferences copies existing destination collection items appended end of collection.                 cellvalue[] cellvalarray = studyvalcol.getcellvalues().toarray(new cellvalue[studyvalcol.getcellvalues().size()]);                 studyreccol.getcellvalues().addall(new arraylist<cellvalue>(arrays.aslist(cellvalarray)));                 break;             }         }     } 

thanks,

chris

collections.copy() doesn't (nor claim to) perform deep copy:

copies of elements 1 list another. after operation, index of each copied element in destination list identical index in source list. destination list must @ least long source list. if longer, remaining elements in destination list unaffected.

it shallow copy (resulting in copied references in each list same set of objects).


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -