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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:17:14+00:00 2026-06-13T13:17:14+00:00

Why do I get original data changed in the calling method, even if copying

  • 0

Why do I get original data changed in the calling method, even if copying the original List using the following in the called method :

originalDatesSerie = datesSerie ;

instead of using :

originalDatesSerie.addAll(datesSerie) ;

The original List is kept as it in the calling method when using addAll in the called method, so result is as expected in that case.

Here is the piece of the ugly code which is Ok (but NOK if using a direct equal assignment) :

    private static HashMap<String, Object> autoScaling(List<Date[]> datesSerie, List<double[]> valuesSerie,
                HashMap<String, Long> xminMax) {

        // Copy original List (required to keep them unchanged)
        List<Date[]> originalDatesSerie = new ArrayList<Date[]> ();
        originalDatesSerie.addAll(datesSerie);//do NOT use "="
        List<double[]> originalValuesSerie = new ArrayList<double[]> ();
        originalValuesSerie.addAll(valuesSerie);//do NOT use "="

...

        // Concat new datas with original datas
        originalDatesSerie.addAll(Xaxis);
        originalValuesSerie.addAll(Yaxis);
}
  • 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-13T13:17:15+00:00Added an answer on June 13, 2026 at 1:17 pm

    In your first example (originalDatesSerie = datesSerie ;) you are assigning a reference to dateSerie to originalDatesSerie, meaning that both are referencing the same ArrayList. When you make a change to an object through one reference or add/delete objects, it is reflected in both.

    In the second example originalDatesSerie.addAll(datesSerie) ;, originalDatesSerie references each of the objects in dateSerie, but the references are a separate set of references (ListArray). When you add objects to originalDatesSerie, you are adding them to a separate collection.

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

Sidebar

Related Questions

Would be possibile to get the original data type after applying the ArrayToStringTransformer to
How can I get the Original Install Date of the Windows using C#?
Original issue Since I changed the version from 1.6.3. to 1.6.4 I get serious
I get a NullPointerException calling a Superclass Method in Subclass Inner Class Constructor... What's
I'm using Flash uploader(uploadify, swfupload) with CodeIgniter, want to get the session data. I
I've managed to get the original filename of a photo stored in the asset-library
GET is a convenient method to post the form id, post the website id
I'm using FMOD library to extract PCM from an MP3. I get the whole
So the problem changed from what it was, i'll leave the original question below
I am using a model-based form to create a form based off a data

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.