You must distinguish between two types of copies: shallow and deep .
While a deep copy allocates a new space for the entire array and all its contents (if it contains links, then a new space is allocated for creating instances with the same values โโof the copied), a shallow copy simply allocates space with the same size of the copied array.
Example:
Array A was allocated to contain only two mutable objects (for example: a list or arraylist), you want to have only a copy of the "extern" array (one that contains two links), or you need a deep copy that will also highlight new instances of the two links contained in A?
In the first case, for example:
A is an array starting with reference 0x0000AA
ElementOne starts at 0x00BBCC
ElementTwo starts at 0x00BBFF
If you do a shallow copy:
B (new array) starts at 0x0000BB, ElementsOne and ElementsTwo will point to old links (0x00BBCC, 0x00BBFF).
If you are doing a deep copy, it not only allocates new space for the array, but also allocates space for storing new instances (new list, new arraylist ...).
Markon
source share