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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:37:46+00:00 2026-05-15T20:37:46+00:00

So I have an ArrayList in java. And what I’m doing is creating a

  • 0

So I have an ArrayList in java. And what I’m doing is creating a new list with updated values. But I want to put those new values into the original ArrayList. This is important because I’m passing the original arraylist reference to an object that I no longer have access to, but I need to keep its contents up to date. Is there any way to make java copy the contents into a current reference? I hope that makes sense.

Also, I’d rather not clear the original arraylist and then loop through it pushing the new contents into it.

I need to do something like this:

ArrayList a;
ArrayList *b = a;
//pass b (the pointer) to something
ArrayList c;
*b = c;

I really hope I got that (pseudo) c++ code correct or I’ll look pretty stupid =P

I can see how I’m not being clear, it’s kind of complicated (this is in android so it’s across a couple activities) so let me see if I can get my point across better.


Class1{
ArrayList a;
method1(){

a = Class2.getA();
method_that_uses_a(a);
}
}

Class2{
ArrayList getA(){

ArrayList a = new ArrayList

a = getDataFromWebsite();

return a;
}

Class1's method1() gets called periodically by another portion of code. But I need the reference to a stay the same, but the contents to change to the new contents.

  • 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-15T20:37:47+00:00Added an answer on May 15, 2026 at 8:37 pm

    I think your question is unclear, what do you mean by

    “And what I’m doing is creating a new list with updated values. But I want to put those new values into the original ArrayList. This is important because I’m passing the original arraylist reference to an object that I no longer have access to, but I need to keep its contents up to date. Is there any way to make java copy the contents into a current reference? I hope that makes sense.”

    When you do

    List a = new ArrayList
    List b = a
    

    you have one ArrayList object, and two references to the object, a and b.

    Also note that there is an addAll method that you can use to add members of one collection to another collection. Note that I believe addAll does not do a deep copy, so if you use it both lists have copies of the same reference. So if list a has references a1, a2, a3, and you do b.addAll(a), b now has references to the objects that a1…a3 point to…

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

Sidebar

Related Questions

I have an ArrayList , which I want to divide into smaller List objects
I have this ArrayList in Java - List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Possible Duplicate: How to convert List<Integer> to int[] in Java? I have an ArrayList
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
I have following Code package cyclist.project; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException;
Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
I have made an ArrayList in Java and put some integers and some doubles
I have an ArrayList of Path values. I need to convert it into String
I have a ArrayList that contains values in the form [ann,john]. I want to
so suppose i have ArrayList<E> X = new ArrayList<E>(); and I pass X into

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.