As part of a larger program I am trying to multiply every value of an Apache Commons MultiKeyMap
by 120. I think I could use an Iterator
, but I believe those only work for normal hashmaps.
What I want to do, in terms of arrays, is this:
int[] array = { 8, 9, 6, 4, 5 }
for (int i = 0; i < array.length; i++) {
array[i] = array[i] * 120;
}
I am not sure how to implement something like this with a MultiKeyMap
. I have looked for solutions, and found a way to iterate a normal HashMap
(Update all values at a time in HashMap):
Iterator it = yourMap.entrySet().iterator();
Map.Entry keyValue;
while (it.hasNext()) {
keyValue = (Map.Entry)it.next();
//Now you can have the keys and values and easily replace the values...
}
However, this works only for a simple <K, V>
map, where I have <K, K, K, V>
. How could I do this with a MultiKeyMap
?
MultiKeyMap
still supports iterators, see the docs:
https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/map/MultiKeyMap.html#mapIterator()
MapIterator it = multiKeyMap.mapIterator();
while (it.hasNext()) {
it.next();
System.out.println(it.getValue());
}