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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:49:58+00:00 2026-05-22T14:49:58+00:00

I have a map object testMap declared as HashMap<String, Test> . Test is a

  • 0

I have a map object testMap declared as HashMap<String, Test>.

Test is a simple class which contains references to an Object and to two String values.

ie,

public class Test {

  private String name;
  private String id;
  private Object val;


public Test(Object val,String name.String id){
  this.val =val;
  this.id=id;
  this.name = name;
}

I want to update the “name” only in the Hash map “testMap.” How can I do this?

  • 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-22T14:49:59+00:00Added an answer on May 22, 2026 at 2:49 pm

    You need to change the visibility of your name property to public or add a setter to it:

    public class Test {
    
      private String name;
      private String id;
      private Object val;
    
    
    public Test(Object val,String name, String id){
      this.val =val;
      this.id = id;
      this.name = name;
    }
    
    public void setName(String name) {
      this.name = name;
    }
    

    Then, to change your name, you need to

    Test test = testMap.get("key");
    if (test != null) {
       test.setName("new name");
    }
    

    If you want to update the Map key also, then you need

    Test test = testMap.remove("oldKey");
    if (test != null) {
       test.setName("newKey");
       test.put("newKey", test);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code private Map<KEY, Object> values = new HashMap<KEY, Object>(); public
I have a spring-hibernate application which is failing to map an object properly: basically
I have an object: map<A*, string> collection; I would like to call the map::find
I have code like this: val dm = List[String]() val dk = List[Map[String,Object]]() .....
Hi: I have a question about how to design and map object class in
I made a servlet which creates a Map Object: Map<String, Integer> data = new
Accessing map inside map with closure, I have a map object the values is
I have a map that represents a DB object. I want to get 'well
I have a Map, that I want to persist. The domain object is something
I've been trying to map an object to a database using SQLAlchemy but have

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.