This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When to use shallow copy and deep copy ?

 
Praveen Kumar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15367
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic