while (true) {
String city = reader.readLine();
if (city.isEmpty()) break;
String family = reader.readLine();
cities.put(city, family);
}
//Print the Map Key, Value Pairs
System.out.println(cities);
String city = reader.readLine();
//Print Family name based on City
System.out.println(cities.get(city));
}
package com.codegym.task.task08.task0829;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/*
Software update
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Map<String, String> cities = new HashMap<String, String>();
// List of addresses
while (true) {
String city = reader.readLine();
if (city.isEmpty()) break;
String family = reader.readLine();
cities.put(city, family);
}
System.out.println(cities);
String city = reader.readLine();
//read city name
String familyName = cities.get(city);
System.out.println(familyName);
}
} //End of Main