forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMapContainsKey.java
More file actions
38 lines (26 loc) · 1016 Bytes
/
HashMapContainsKey.java
File metadata and controls
38 lines (26 loc) · 1016 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
34
35
36
37
38
package com.zetcode;
import java.util.HashMap;
import java.util.Map;
public class HashMapContainsKey {
public static void main(String[] args) {
Map<String, String> capitals = new HashMap<>();
capitals.put("svk", "Bratislava");
capitals.put("ger", "Berlin");
capitals.put("hun", "Budapest");
capitals.put("czk", "Prague");
capitals.put("pol", "Warsaw");
capitals.put("ita", "Rome");
String key1 = "ger";
String key2 = "rus";
if (capitals.containsKey(key1)) {
System.out.printf("HashMap contains %s key%n", key1);
} else {
System.out.printf("HashMap does not contain %s key%n", key1);
}
if (capitals.containsKey(key2)) {
System.out.printf("HashMap contains %s key%n", key2);
} else {
System.out.printf("HashMap does not contain %s key%n", key2);
}
}
}