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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:12:59+00:00 2026-05-27T04:12:59+00:00

Okay, I know this question has been asked before: Previous Question I have also

  • 0

Okay, I know this question has been asked before: Previous Question

I have also looked into a few other threads and websites and they all seem to create more questions than answers.

Josh Bloch on Design – an article discussing .clone();

But I still couldn’t work out the answer to my problem.

When I clone my 2D array:

values = Map.mapValues.clone();

I still cannot safely modify the content of values as it still modifies the content of Map.mapValues.

Is there actually a way to copy an array which is more efficient than me just re-creating one from scratch each time?

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-27T04:13:00+00:00Added an answer on May 27, 2026 at 4:13 am

    In Java, a 2D array is an array of references to 1D arrays. Map.mapValues.clone() only clones the first layer (i.e. the references), so you end up with a new array of references to the same underlying 1D arrays. This is why your attempt to use clone() did not work.

    One way to fix this is by also cloning the underlying 1D arrays:

    byte[][] values = Map.mapValues.clone();
    for (int i = 0; i < values.length; i++) {
      values[i] = values[i].clone();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I know this question have been asked plenty of times already, but I
Okay I know I asked about this before, and the answer was basically cache
Alright, I know questions like this have probably been asked dozens of times, but
Okay, two admissions here, one is I'm sure this question has been answered and
Okay I know this is a really lame question because Starbasic is a really
Okay, this is (probably) a very simple question, but I am afraid I know
Okay so this is sort of a double question so I'll split it into
Okay the question title may not have made sense... mostly because I don't know
Possible Duplicate: Hide facebook app from search Okay, I know that this question was
Okay. I know this looks like the typical Why didn't he just Google it

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.