I am trying to write a procedure do the deep copy of List<List<Integer>>
, and I am doing like this:
public static List<List<Integer>> clone(final List<List<Integer>> src)
{
List<List<Integer>> dest = new ArrayList<List<Integer>>();
for( List<Integer> sublist : src) {
List<Integer> temp = new ArrayList<Integer>();
for(Integer val: sublist) {
temp.add(val);
}
dest.add(temp);
}
return dest ;
}
Is this a good way to do? Is it possible to get rid of the inner loop? The fact is that each of the inner sub-lists can grow to large lengths.
>`s with exactly same values but every structure will have different hashcode. So that I can differentiate among them. I will call the `clone()` procedure above many times in different places.
– ramgorur Jun 19 '17 at 22:10