-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBirthdayBook.java
More file actions
33 lines (20 loc) · 820 Bytes
/
Copy pathBirthdayBook.java
File metadata and controls
33 lines (20 loc) · 820 Bytes
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
import java.util.HashMap;
public class BirthdayBook {
public static void main(String[] args) {
HashMap <String, String> birthdays = new HashMap<>();
birthdays.put("Alice", "Jan 5");
birthdays.put("Bob", "Feb 20");
birthdays.put("Alice", "Jan 6");
birthdays.put("Charlie", "Mar 15");
System.out.println("Alice's birthday is: " + birthdays.get("Alice"));
// Printing Alice's birthday from the birthdays HashMap
System.out.println("All birthdays: " + birthdays);
// Printing all the birthdays
if (birthdays.containsKey("David")) {
System.out.println("David's birthday is: " + birthdays.get("David"));
// If the key(David) exists, it will execute this command
} else {
System.out.println("David not found.");
}
}
}