• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

shallow copy vs deep copy?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any one plz explain what is shallow copy and deep copy? and how does it relate with clone() method?

Thanks in advance,
-Aman
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic