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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:40:29+00:00 2026-06-18T07:40:29+00:00

This is a little confusing question for me to express, but I’ll do my

  • 0

This is a little confusing question for me to express, but I’ll do my best.

So:

ArrayList<Object> fieldList = new ArrayList<Object>(); 

I then dump a lot of different variables to this array:

fieldList.add(objectsURL);   //string 

 fieldList.add(X);  //int 

 fieldList.add(Y); //int 

 ... 

If I change the variable, the values in the array change
too-confirming the array stores a reference to the memory, rather
then value itself.

However, if I then retrieve data from the array then set that…

Object object = ((String)this.fieldList.get(0)); 

Then set object

object = "meeep!" 

objectsURL is not set to “meep!” but rather it retains its original
value.

I assume this is because the “object” is not referencing the original
variable anymore, that instead its pointing to a new immutable string
in the memory.

All expected Java behavior I think….but then, how would I go about
setting the actual original variable? is this possible in java?.

So, in other words. Given only access to “fieldList” is it possible to change the value of
“objectsURL”?

So, if:

String objectsURL = "www.google.com"
fieldList.add(objectsURL); 

Is there a way to set objectsURL to “www.stackoverflow.com” using only a reference from fieldList?
I dont want to change the fact that fieldList contains “objectsURL”, I want to change what string the variable “objectsURL” actualy contains.


If not, is there an alternative method to achieve the same thing?

I hope my question explains the problem well enough.

My use-case is trying to make a serialization/
deserialization system for a bunch of my objects. I was hoping to put
all the fields into a arraylist I could retrieve for both reading and
writing….thus avoiding having to hard-code long lists of
field[0]=blah and blah=field[0] and then going though constant pains
of needing to renumber them each time I add a new field before
another.

(I cant use Javas inbuilt serialization, as I am using GWT and this is client side only.)

Thanks,

  • 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-18T07:40:30+00:00Added an answer on June 18, 2026 at 7:40 am

    I assume this is because the “object” is not referencing the original variable anymore, that instead its pointing to a new immutable string in the memory.

    Correct, each time you use the assignment operator = on an object you change the object it refers to, not the object itself.

    To change the values in the List, you use the .set method of an ArrayList

    this.fieldList.set(0, newValue);

    Since your variable is a String, there is no way you can change the String-variable through the list

    Your alternatives:

    • using a char-array

      List myList = new ArrayList();
      char[] charArray = "My String".toCharArray();
      myList.add(charArray);
      charArray[0] = 'A';
      String theString = new String(myList.get(0)); // "Ay String"

    If you use a char-array, make sure that the length of the array is enough to contain the number of characters you want to have in the future, because to change the length of the array you will need to create a new array (array lists can be expanded dynamically, arrays can not)

    • Embed the String inside your own class (I have ignored getters and setters here)

      class MyString {
          public String value;
          public MyString(String value) {
              this.value = value;
          }
      }
      MyString myStr = new MyString("some value");
      list.add(myStr);
      ((MyString) list.get(0)).value = "a new value";
      System.out.println(myStr.value); // will print "a new value"
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Title to this question is probably a little confusing, but let me try
My question may sound a little confusing, but I hope after reading this it
The question maybe a little confusing, but it's hard to make clear this question
Sorry if the question title is a little confusing, but I'm not sure exactly
Maybe is a little confusing question but here is an explanation by the code:
I know the title is a little confusing, but the best way to describe
firstly, I apologize if my question sounds little confusing, I will try my best
This might get a little confusing as I have tried everything to make this
This one is a little confusing to me. I'm running a LAMP server with
This one might be a little confusing. I'm using AMCharts with rails. Amcharts comes

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.