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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:08:04+00:00 2026-06-11T17:08:04+00:00

Map<String, Data> map = new HashMap<String,Data>(); map.put(jan, new Data(RED,M4A1,5,0,0)); How can I change the

  • 0
Map<String, Data> map = new HashMap<String,Data>();
map.put("jan", new Data("RED","M4A1",5,0,0));

How can I change the value RED of the Data object?, without getting all the information out of the map with the key and putting it back in, like this:

map.put("jan" new Data("Blue",
      map.get("jan").Brand,
      map.get("jan").Storage,
      map.get("jan").Sold,
      map.get("jan").Bought)); 

So how can i change 1 value of the Data Object instead of redo them all?

  • 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-11T17:08:05+00:00Added an answer on June 11, 2026 at 5:08 pm

    It depends on whether Data is mutable. For example, you may be able to write:

    Data data = map.get("jan");
    data.setColor("Blue");
    

    Don’t forget that the map only contains a reference to the object, so if you change the data within the object, that change will be seen if someone fetches the reference from the map later.

    Or if it’s immutable, it could potentially have a withColor method, so you could write:

    Data data = map.get("jan");
    map.put("jan", data.withColor("Blue"));
    

    Without knowing more about your Data type (which I hope isn’t the real name of your class) it’s hard to say any more.

    (I also hope your class doesn’t really have Pascal-cased fields, and I hope those fields are private, but that’s a different matter…)

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

Sidebar

Related Questions

i have some listview and SimpleAdapter List<HashMap<String, Object>> dataList = new ArrayList<HashMap<String, Object>>(); HashMap<String,
for(int i=0; i<jArray.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); json_data =
private static synchronized String[][] map2data(Map<String, Object> map) { if (map != null) { String[][]
I'm making use of a List<? extends Map<String,?>> that I populated with data. cursor.moveToFirst();
I want to make list object as my data source, can you tell me
public class ABC extends ListActivity { static final ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>(); @Override
I have an unordered map: class O(val a: Int) Map[String, List[O]] which I'd like
I have this as a return type in Scala Map[String, Seq[Map[String, Seq[MyClass]]]] I have
I have the following function: func addCatsToMap(m map[string][]CatHouse, meowId int, treats Set, dog *Dog)
I have a java map with string in its key and integer in its

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.