scripti

Shallow Copy vs Deep Copy

In the previous article, we saw how object is being instantiated and how the memory allocation happening in heap part of the memory. Understanding this concept is vital to understand the important concept of shallow and deep copy of objects. Please refer to the class object creation article before continuing further.

Refer the below images for the shallow copy and deep copy differences



Shallow Copy

Diagram showing shallow copy concept in Java

Deep Copy

Diagram showing deep copy concept in Java