How can I update values in a map?

I am using a TreeMap<Integer,Object>() to store values. Now my Object has a component, Object.value(), which keeps getting incremented as per values read from a file. So, I evaluate whether the key exists and need to update value. I do not understand how I can update values in a Map in Java. I cannot just replace the whole record, as new values need to be added to the existing record value. Is there a better way to do this than using a map? I used a map because I will keep searching for the keys. Any suggestions?


Well using a map is correct if you want to be able to quickly access your key-value pairs. If you're values are just MyObjects with a .value(), can't you get the object and reset that value?

MyObject myObj = treeMap.get(key);

I'm using MyObject here as the poster was using Object to denote an example type.

Need Your Help

Connection timeout on query on large table

c# mysql timeout

I have a problem with a script timing out while fetching data form a query on large table.

EXTJS Combobox tooltip

extjs combobox

Am having a combobox which has its data populated from a SQL database, using a store. I want to display the tooltips for each of the item in the combobox and these tooltips are also stored in the