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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 13869

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
copies of objects
need your help about a cast about cloneable.!!!(jcjp07-Q119)
Doubts in cloning concept.
Deep Copies?
What is the difference between the deep copy and shallow copy in Object.clone()