Link to home
Start Free TrialLog in
Avatar of AndyC1000
AndyC1000

asked on

Get values for a key in multiple TreeMaps

Dear all,

I have a number of TreeMaps <Long, Integer> each containing values for a specific dataset.

Map<Long, Integer> Heating = new TreeMap<>();
Map <Long, Integer> Cooling = new TreeMap<>();
Map <Long, Integer> Appliances = new TreeMap<>();
etc.

I am now trying to write out the values to a file line by line.  

Usually I iterate through a map in the following way but not sure how to get each value for the same long (Date/TIme) into a string, i.e. Date key , Heating value, Cooling value, Appliances value.

Thanks

Iterator<Map.Entry<Long, Integer>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
    Map.Entry<Long, Integer> entry = entries.next();
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial