What is the difference between shallow copy and deep copy in Java?

Java 8Object Oriented ProgrammingProgramming

When we copy an object, a shallow copy is where only the outer object is copied. For example, if we have an object named sample and it contains another object named subSample then if you copy this only the contents of the sample are copied.

When we copy an object deep copy is where whole object structure is copied i.e. if you copy sample the contents of both sample and subSample were copied.

Updated on 30-Jul-2019 22:30:20