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 6379191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:06:21+00:00 2026-05-25T02:06:21+00:00

I have deep nested structures, and methods like remove(<Something>) , contains(<Something>) etc. rely on

  • 0

I have deep nested structures, and methods like “remove(<Something>)“, “contains(<Something>)” etc. rely on access to the original reference in order to remove it etc. (a copy of the reference won’t do).

How have people best worked around this so they can still conveniently add, remove, test for etc. the object they want, within different arbitrary methods and constructors etc., without adding any unnecessary complexity or any unnecessary loss in performance?

  • 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-25T02:06:22+00:00Added an answer on May 25, 2026 at 2:06 am

    Methods like remove and contains work fine with pass by value. The reason is that the even though the references are copied, they copy has the same value of the original. Just look at the Collections API. If you do something like (psuedocode)

    List list = new List();
    list.add(object1) // assume you have an object1 reference
    

    and then you do

    myRemove(list, object1);
    

    both list and object 1 are passed by value, so in the myRemove method they are copies of the original reference. If in myRemove you do

    list.remove(object1);
    

    the object is still removed from the list no problem. Furthermore, since the list and object1 references in both scopes point to the same underlying objects, the list reference in the calling scope refers to the list that has the object removed.

    The only time you would need pass by reference semantics is if you want to modify a reference in a method and have the modification apply in the scope that called the method.

    So if you want to do

    List myList = new List(); 
    changeList(myList); 
    

    and have changeList change where myList points in the calling scope, it wont work without some trickery. The trickery is called double indirection. Basically, you create an object that has an instance of what you want to be able to access with pass by reference semantics, and you pass the container object around.

    So

    class MyContainer {
        List list
    }
    

    now you can pass an instance of MyContainer into a method, and change the list value, and in the calling scope where the list points will be changed. Note that you are not doing anything special here, everything is still pass by value.

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

Sidebar

Related Questions

I have a nested array (only one level deep) like this: $a = array(
Please see screenshot: Goal: id like to have comments nested 1 level deep The
I have a fairly large, three level deep, menu consisting of nested lists like
If I have deep nested unordered list and I have a reference to the
I have this nested loop that goes 4 levels deep to find all the
So I have some nested lists (only one level deep) and I'm running into
I have somewhat deep Json structure like below incoming over the wire into C#
Explanation: Let's say I have an object graph that's nested several levels deep and
I have nested ajax accordion web controls (nested 3 deep or sometimes 4 deep)
i am using the itertools.product function. i have a 2-deep nested list, which is

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.