Created
February 11, 2017 16:36
-
-
Save loslch/669370a0f8e129ed62b083f791a14155 to your computer and use it in GitHub Desktop.
PhoneBook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PhoneBook.java | |
public class PhoneBook { | |
Map<String, List<String>> map = new HashMap<String, List<String>>(); | |
public void load(String filename) throws IOException { | |
try { | |
BufferedReader r = Files.newBufferedReader(Paths.get(filename)); | |
String line = null; | |
while ((line = r.readLine()) != null) { | |
String[] values = line.split(","); | |
List<String> list = map.get(values[0]); | |
if (list == null) { | |
list = new ArrayList<String>(); | |
} | |
list.add(values[1]); | |
map.put(values[0], list); | |
} | |
r.close(); | |
} catch (FileNotFoundException e) { | |
throw e; | |
} catch (IOException e) { | |
throw e; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment