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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:52:51+00:00 2026-05-24T06:52:51+00:00

A quick question which maybe is lame. In the following code: Map<Integer, Double[]> dataMap

  • 0

A quick question which maybe is lame.

In the following code:

Map<Integer, Double[]> dataMap = new Map<Integer, Double[]>();
dataMap.put(1, new Double[]{100,100});
Double[] dob = dataMap.get(1);
dob[0] = 100;
dob[1] = 200;
dataMap.put(1, dob);

Is the last “dataMap.put” instruction necessary? or will the dataMap.get(1) yield a reference to the array which will then be modified directly in the later statements.

I know that, in the case of mutable objects (e.g. Map), Map.get() will give me the reference to the desired object, however with an array of Doubles (whose element type e.g. Double are immutable) I am not sure if I get a reference to the array in the Map.

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-05-24T06:52:51+00:00Added an answer on May 24, 2026 at 6:52 am

    No, the final statement isn’t necessary – because the map only contains references to arrays, as you’ve mentioned. An array is a mutable object, even though Double isn’t – it’s like having an object with a setName(String) method – just because String is immutable, the container type isn’t.

    Note that if you do this, another thread1 may see half the change (i.e. the setting of the first element to 100) without seeing the second element set to 200. Is that okay? If not, you could think about creating a new array instead:

    Map<Integer, Double[]> dataMap = new HashMap<Integer, Double[]>();
    dataMap.put(1, new Double[]{100,100});
    // Other stuff...
    
    // Replace value in map with a reference to a different array.
    Double[] dob = new Double[] { 100, 200 };
    dataMap.put(1, dob);
    

    1 This is assuming you’re using a thread-safe map to start with, of course…

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

Sidebar

Related Questions

A quick question. I have the following code which gets the mod date of
I have a quick question, suppose I have the following code and it's repeated
Just a quick question here. I have a program in which I need to
Quick question, If I want to document some code on a basic HTML and
a quick question which may or may not be easily answered. Currently, in order
Quick question : I have a PHP script which query Pinnacle Cart API through
quick question, I am building a simple trigger which purpose is to decrement the
just a quick question. I've got this table in a Word template which have
Just a quick question. I have a system which contains some silverlight elements to
Quick question which I fear has a short and disappointing answer but alas I

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.