This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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
jQuery in Action, 3rd edition