Forums Register Login

shallow copy vs deep copy?

+Pie Number of slices to send: Send
Can any one plz explain what is shallow copy and deep copy? and how does it relate with clone() method?

Thanks in advance,
-Aman
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1346 times.
Similar Threads
need your help about a cast about cloneable.!!!(jcjp07-Q119)
Cloneable and deep copy.
Diffarence between shallow copy and deep copy
shallow copy and deep copy
What is the difference between the deep copy and shallow copy in Object.clone()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:13:14.