File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes When to use shallow copy and deep copy ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "When to use shallow copy and deep copy ?" Watch "When to use shallow copy and deep copy ?" New topic
Author

When to use shallow copy and deep copy ?

Praveen Kumar
Ranch Hand

Joined: Nov 06, 2006
Posts: 133
Hi

I know concepts about shallow copy and deep copy. Just i want to know when we will go for shallow copy and deep copy ?. Please suggest some examples that would be great.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14428
    
  23

It depends entirely on what the needs are for the program you are writing - there's no general answer to this question.

I'd avoid copying objects as much as possible - it costs performance and memory. If you make your data objects immutable, you'll never need to copy them.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: When to use shallow copy and deep copy ?