I have two linkedHashmaps which are the same length with the same key names but the values are different. for example :
Map<String, Double> map1= new LinkedHashMap<String, Double>();
map1.put("A", 2.3);
map1.put("B", 6.1);
map1.put("C", 5.3);
Map<String, Double> map2= new LinkedHashMap<String, Double>();
map2.put("A", 10.3);
map2.put("B", 60.1);
map2.put("C", 0.3);
How would I multiply each value from map1 with the same corresponding key in map2 (A 2.3*10.3, B 6.1*60.1 etc etc) and save the results to a new linkedHashMap?
I tried this with no luck.
Map<String, Double> map3= new LinkedHashMap<String, Double>();
double valueMap1 = map1.get(key);
double valueMap2 = map2.get(key1);
for(String key : map1.keySet())
for(String key1 : map2.keySet()){
if(map1.containsKey(key1)){
double newValue =valueMap1* valueMap2;
map3.put(key1, newValue);
}
}