I’m working on a program for class. Using a TreeMap to store IDs (String – Key) and earnings amounts (double – value). I’m importing the values from a text file using a Scanner. My problem at the moment is that I need the values to accumulate rather than overwriting with the last value read. So my question is how do you use a Map to do calculations like that? Any help would be appreciated.
Share
When adding a new value to your map, if the key already exists, you can get the associated value, add the new value to it, and put it back into the map. Example: