• 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

Difference between Shallow copy and Deep Copy in Java

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sir/Mam,

Explain What is the Difference between Shallow copy and Deep Copy in Java.please provide some examples.

Regards,
Mahi.
 
Greenhorn
Posts: 3
Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Allways wanted to do this

http://lmgtfy.com/?q=What+is+shallow+copy+and+deep+copy+in+Java%3F&l=1
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good one, Pegel!
 
Ranch Hand
Posts: 52
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

- Shallow copy means copy only intermediate objects, pointers, references, handles etc and is created very fas.
- copies this object refer to the same object, change in its state will be visible in all copies of this object.

- deep copy means real object copy, it take more times and resources but object and his copy are independent of each.
- Object changes have no effect on the copies


Sorry for my English i know that is not perfect.
 
pegel van de Wiel
Greenhorn
Posts: 3
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, had my fun, a little more constructive:
Dawid has said it all, but keep in mind, for the non fast (i.e. deep copy) make sure to implement Cloneable interface and override the clone() method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic