Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8414535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:11:48+00:00 2026-06-10T01:11:48+00:00

OK when doing a deep copy obviously references should not be copied. However, if

  • 0

OK when doing a deep copy obviously references should not be copied. However, if the object being copied contains objects that themselves are references to to the same object should that be maintained or should the data just be copied.

Example

public class Program() {
    public void Main(String[] args) {
        Person person = new Person();
        person.setName("Simon");

        List<Person> people = new ArrayList<Person>();
        people.add(person);
        people.add(person);
        people.add(person);

        List<Person> otherPeople = magicDeepCopyFunction(people);

        otherPeople.get(0).setName("Adam");

        // should this output 'Adam' or 'Simon'?
        System.out.println(otherPeople.get(1)); 
    }
}

I can see arguments for both but I am wondering what the consensus was.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:11:49+00:00Added an answer on June 10, 2026 at 1:11 am

    A true deep copy creates copies of everything all the way down the tree of references.

    If B is a deep copy of A, any changes you make to A will not be visible via B.

    Most deep copy algorithms would not notice that in your example, all three members of people are references to the same person. A typical deep copy algorithm would create three new Person objects.

    However, it’s not all that common to see a true deep copy, because it’s hard to program reliably (except for very strictly defined data structures), and expensive at runtime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to serialize an object that contains an interface. However, interfaces cannot
I want to make a Deep Copy of some Object[] and ArrayList How can
I was reading up on performing a deep-copy of an array correctly, however I
I'm wondering if there is a recommended way of doing deep clone/copy of instance
So lets say I want to make a deep copy of an object, but
Is there any built-in function that allows me to deep copy an NSMutableArray ?
At first I thought arr.slice(0) was doing a deep unreferenced copy, but it is
I am having trouble doing a deep copy of my doubly linked list. This
What am I doing wrong? Simple recursion a few thousand calls deep throws a
Doing some homework here (second assignment, still extremely green...). The object is to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.