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?
I am using a TreeMap<Integer,Object>() to store values. Now my Object has a component,
Share
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
MyObjectswith a.value(), can’t you get the object and reset that value?I’m using MyObject here as the poster was using
Objectto denote an example type.