-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
42 lines (24 loc) · 761 Bytes
/
Copy pathtest.java
File metadata and controls
42 lines (24 loc) · 761 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
39
40
41
42
package hashmaps;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
;
public class test {
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<>();
map.put("key", 1);
if (map.containsKey("key")) {
System.out.println("it has");
}
int v = map.get("key"); // null pointer exp when
map.remove("key"); // no exception if not exists.
int l = map.size();
Set<String> keys = map.keySet();
for (String str : keys) {
System.out.println(str);
}
for (Entry<String, Integer> mp : map.entrySet()) {
System.out.println(mp.getKey() + " " + mp.getValue());
}
}
}