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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:14:45+00:00 2026-06-03T07:14:45+00:00

I have an Hashmap <integer, Arraylist<Double>> . I would like to make a copy

  • 0

I have an Hashmap <integer, Arraylist<Double>>. I would like to make a copy of it. I was thinking of using method clone of hashmap. After going through the javadoc, it
says the following:

clone
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned. 

What does this shallow copy means? I want a separate matrix , whose values does not change while updating the value of original matrix.

Moreover why does,

    if( hm1 == hm1.clone()) 

returns false?

  • 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-03T07:14:47+00:00Added an answer on June 3, 2026 at 7:14 am

    The shallow copy means that only the map object is created new, but its values are not cloned, i.e. the copy contains references to the old entries. So to “deep clone” a map you would need to do:

    1. create a new hash map object
    2. iterate over all entries in the old map and add the (deep) clones of the key and value to the new map

    Because == compares the object reference, not the content of the map.

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

Sidebar

Related Questions

I have a java Hash, the structure is like this: HashMap<Integer, ArrayList<String>> finalMap =
I have a nested map: Map<Integer, Map<Integer, Double>> areaPrices = new HashMap<Integer, Map<Integer, Double>>();
I have a HashMap that I'm using in Processing and I'd like to increment
after I create a new object : Map<Float,Integer> m = new HashMap()<Float,Integer>; I have
I would like to shuffle values in an HashMap. I have following type of
If I have a Map like this: HashMap<Integer, ComparableObject> map; and I want to
I have a variable of type Hashmap <String,Integer >. In this, the Integer value
if i have two hashmaps, of types HashMap<Integer, HashMap<Integer, Police>> time_id_police; HashMap<Integer, HashMap<Integer, Ambulance>>
i have a hashmap where every key has many values(stored in a arraylist). How
I have a class Foo which overrides equals() and hashCode() properly. I would like

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.