-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneBook.java
More file actions
40 lines (34 loc) · 1.14 KB
/
Copy pathPhoneBook.java
File metadata and controls
40 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.*;
public class PhoneBook {
private Map<String, ArrayList<String>> book;
public PhoneBook() {
book = new HashMap<>();
book.put("Petrov", new ArrayList<>(Arrays.asList("89000000000")));
book.put("Ivanov", new ArrayList<>(Arrays.asList("89000000001", "89000000002")));
book.put("Smirnov", new ArrayList<>(Arrays.asList("89000000003")));
}
public Map<String, ArrayList<String>> getBook() {
return book;
}
public void add(String name, String phone){
if (!book.containsKey(name))
book.put(name, new ArrayList<>(Arrays.asList(phone)));
else {
ArrayList<String> list = book.get(name);
list.add(phone);
book.replace(name, list);
}
}
public void add(String name, ArrayList<String> phones) {
if (!book.containsKey(name))
book.put(name, phones);
else {
ArrayList<String> list = book.get(name);
list.addAll(phones);
book.replace(name, list);
}
}
public ArrayList<String> get(String name){
return book.get(name);
}
}