This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes shallow copy vs deep copy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "shallow copy vs deep copy?" Watch "shallow copy vs deep copy?" New topic

shallow copy vs deep copy?

Aman Verma

Joined: May 10, 2005
Posts: 15
Can any one plz explain what is shallow copy and deep copy? and how does it relate with clone() method?

Thanks in advance,
Chit Ming Chong
Ranch Hand

Joined: Sep 09, 2004
Posts: 49
shallow copy copies only the reference. deep copy copies the content referrenced. You can override the clone method to do a shallow or deep copy although a deep copy is generally assumed.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
To explain a little further. Imagine if you haad an ArrayList full of JButtons. With a shallow copy, you would have two ArrayLists but still the same number of Jbutton objects. With a deep copy, the ArrayList would be copied and so would all the items in the ArrayList. So if you started with 20 JButtons in one ArrayList you would now have 40 JButton objects in two ArrayLists.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: shallow copy vs 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 and deep copy
need your help about a cast about cloneable.!!!(jcjp07-Q119)
Cloneable and deep copy.