jQuery in Action, 2nd edition*
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.
 
Consider Paul's rocket mass heater.
 
subject: shallow copy and deep copy
 
Similar Threads
Diffarence between shallow copy and deep copy
What is the difference between the deep copy and shallow copy in Object.clone()
shallow copy vs deep copy?
need your help about a cast about cloneable.!!!(jcjp07-Q119)
Cloneable and deep copy.