File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "shallow copy and deep copy" Watch "shallow copy and deep copy" New topic

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
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
shallow copy:
you only copy the reference to an object
deep copy:
you copy the state of an object to a different object.
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
I agree. Here's the link:
subject: shallow copy and deep copy
It's not a secret anymore!