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

  • Home
  • SEARCH
  • 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 7037777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:35:09+00:00 2026-05-28T01:35:09+00:00

Examine the following code: Object object = new Object(); objectList.add(object); objectListTwo.add(object); Is there any

  • 0

Examine the following code:

Object object = new Object();
objectList.add(object);
objectListTwo.add(object);

Is there any way to get both arrays to point to the same object, such that when I change object in one array, it changes in the other?

Thanks for your help!

EDIT: Turns, out my above code does exactly that. Problem was elsewhere in my code. My apologies for my confusion…

  • 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-05-28T01:35:10+00:00Added an answer on May 28, 2026 at 1:35 am

    Depends what you mean by “change.” If you mean change as in calling setters and mutating the object, then those changes are observed. If you mean change as in completely reassigning or overwriting the variable (or reference), those changes are not observed.

    Put it simpler, say you have one object, one array.

    Foo foo = new Foo();
    Foo[] foos = new Foo[1];
    foos[0] = foo;
    

    The item in the array and the variable each reference the same Foo.

    foo.setBar(7);
    int bar = foos[0].getBar(); // will get 7
    

    The change to the object referenced by foo is observed inside the array.

    foo = new Foo();
    foo.setBar(94);
    bar = foos[0].getBar(); // will not get 94
    

    This change is not observed inside the array, as foo has been reassigned. Its setter is now mutating a different object entirely.

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

Sidebar

Related Questions

Is there a way to examine the contents of a DataTemplate in code? I
Are there any utilities that can examine a set of managed assemblies and tell
Is there a better way than examine them pixel by pixel?
Let's examine the MSIL code generated for the following generic method: public static U
I am trying to examine the content of a NSDataDictionary using the following code:
Please examine the following code: if (foo->bar == NULL); foo->bar = strdup("Unknown"); I spent
Examine the following code: This works: T *p = (std::find( this->first(), this->last(), *pPos ));
The following code examines the behaviour of the float() method when fed a non-ascii
I have the following code in my app: public static final boolean DEBUG =
I'm using a static analyzer in Eclipse to examine my code. One class, foo,

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.