Currently I have 6 HashMaps that contain the name of cities and values of different categories but I need to sum up the values of each city for every category, that is:
HashMap<String, Integer> HeatHMap = new HashMap<>();
HashMap<String, Integer> DaylightHMap = new HashMap<>();
HashMap<String, Integer> PrecitipationHMap = new HashMap<>();
HashMap<String, Integer> DaylightHMap = new HashMap<>();
HashMap<String, Integer> WindHMap = new HashMap<>();
HashMap<String, Integer> MoistureHMap = new HashMap<>();
Where HeatHMap contains:
Cities Values
Tucson 23
Hermosillo 47
Boulder 25
and DaylightHMap contains:
Cities Values
Tucson 43
Hermosillo 37
Boulder 75
Right now, I need to add up the values of each city, i.e., Hermosillo, for each category and save the values into another HashMap, so the result would be something like:
Cities Values
Tucson 78 = (23+43+...+n)
Hermosillo 160 = (47+37+...+n)
....
I was thinking in adding every HashMap into an ArrayList and then get access to each city but I realized having a HashMap into a list would not be a good approach to tackle this problem. So far, I have:
public void verifyTheWinner(
HashMap <String, Integer> Table1, HashMap <String, Integer> Table2,
HashMap <String, Integer> Table3, HashMap <String, Integer> Table4,
HashMap <String, Integer> Table5, HashMap <String, Integer> Table6)
{
List<HashMap> categories = new ArrayList<HashMap>();
categories.add(Weather);
categories.add(SeaWeather);
categories.add(Rainfall);
categories.add(Sunshine);
categories.add(Prices);
categories.add(AvgStd);
HashMap<String, Integer> citiesAndValuesTotal= new HashMap<>();
for (int i=0; i<categories.size(); i++){
......
}}
My questions are:
How can I perform arithmetic operations such as addition of values for each city and then saving them into a new HashMap?
Is there another Collection that I can use to accomplish this goal or is HashMap the best approach to solve this problem?
Thanks for your support, please ask me for more details if you need them. Every answer is welcome.