Skip to content

Instantly share code, notes, and snippets.

@loslch
Created February 11, 2017 16:36
Show Gist options
  • Save loslch/669370a0f8e129ed62b083f791a14155 to your computer and use it in GitHub Desktop.
Save loslch/669370a0f8e129ed62b083f791a14155 to your computer and use it in GitHub Desktop.
PhoneBook.java
// 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