Advertisement
plamen911

Untitled

Jan 21st, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.util.LinkedHashMap;
  3. import java.util.Map;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) throws IOException {
  7.  
  8.         LinkedHashMap<String, LinkedHashMap<String, Integer>> map = new LinkedHashMap<>();
  9.         LinkedHashMap<String, Integer> nestedMap = new LinkedHashMap<>();
  10.  
  11.         String country = "Bulgaria";
  12.         String city = "Sofia";
  13.         int population = 1000000;
  14.  
  15.         nestedMap.put(city, population);
  16.         map.put(country, nestedMap);
  17.  
  18.         map.entrySet().forEach(entry -> {
  19.             //System.out.printf("%s (total population: %d)%n", entry.getKey(), // TO DO Finish here);
  20.             for (LinkedHashMap<String, Integer> linkedHashMap : map.values()) {
  21.                 for (Map.Entry<String, Integer> cityMap : linkedHashMap.entrySet()) {
  22.                     System.out.printf("%s (total population: %d)%n", entry.getKey(), cityMap.getValue());
  23.                 }
  24.             }
  25.         });
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement