File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Murach's Java Servlets and JSP this week in the Servlets 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

When to use shallow copy and deep copy ?

Praveen Kumar
Ranch Hand

Joined: Nov 06, 2006
Posts: 133

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: 14074

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 7 API documentation
Scala Notes - My blog about Scala
I agree. Here's the link:
subject: When to use shallow copy and deep copy ?
Similar Threads
Deep Copies?
copies of objects
need your help about a cast about cloneable.!!!(jcjp07-Q119)
Doubts in cloning concept.
What is the difference between the deep copy and shallow copy in Object.clone()