File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes shallow copy and deep copy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "shallow copy and deep copy" Watch "shallow copy and deep copy" New topic
Author

shallow copy and deep copy

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
What is the difference between shallow copy and deep copy
Regards,
aakash
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
shallow copy:
you only copy the reference to an object
deep copy:
you copy the state of an object to a different object.
Olli
Gaurav Mac Mathur
Ranch Hand

Joined: Feb 19, 2002
Posts: 47
to be more eloberate if a Object A holds a refrence to another object B.
In shallow copy when the parent object A is copied in some new variable A1. A and A1 will hold the same refrence of B.
In deep copy the Object is also copied to a new Object when Copy of A is Made.
This is normally taken care by the Clone method.
This is why is is Advicable for every object to have
equals, clone , toString
methods.....
Cheers
Gaurav.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: shallow copy and deep copy