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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:24:16+00:00 2026-06-13T17:24:16+00:00

I have a class containing Map whose key is string and value is object

  • 0

I have a class containing Map whose key is string and value is object of another class.

          Class Employee {
               String name;
          }

          Class Company {
              Map<String, Employee> m =new HashMap<String, Employee>();
          }

I have two Company objects obj1 and obj2, where I want to copy the map from one object to another object.

If I do any of the below things,

         obj1 = obj2  or    
         obj1.setM(obj2.getM())   // assume we have setters and getters

now if I manipulate obj1’s map, making the any of the value to point to different object of Employee for same Company object that obj2 has, where obj2’s map is also getting affected.

Is there any way (other than copying key and value to new map and assigning it to object), where we can copy the map contents to another object’s map such that manipulating one map doesnot affect other map. Any suggestions are really appreciated.

  • 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-13T17:24:18+00:00Added an answer on June 13, 2026 at 5:24 pm

    Try:

    obj1 = HashMap<Employee, Company> obj2.clone();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class library containing several structures each consisting of several value and
I have a class A containing two pointers to objects of another class B.
I have seen an example of Singleton class object where it has a map
I have a map class, which contains a vector containing MapEntitys. MapEntity is a
If #box doesn't have a containing div with a class of current-map , then
I have a class containing a collection of items. For convenience I've provided GetCurrentItem
I have a class containing Linq To SQL objects that are used to populate
I have a class containing several properties (all are strings if it makes any
I have an example class containing two data points: public enum Sort { First,
I have a Shape class containing potentially many vertices, and I was contemplating making

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.