I am trying to add specific values to a map in Java
, where the key is quite complex, but the value is a simple Double.
I am currently using where foos is an instance of java.util.TreeMap<Foo, Double>
, and amount
is Double
, a code like:
for (java.util.Map.Entry<Foo, Double> entry : foos.entrySet()){ foos.put(entry.getKey(), entry.getValue() + amount); }
but it looks pretty dirty because I need to reinsert the element and I am worried about the validity of the iterator.
Is there a better way to do this? I am using the latest version of Java.
source share