-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMapExam.java
More file actions
49 lines (33 loc) · 1.09 KB
/
HashMapExam.java
File metadata and controls
49 lines (33 loc) · 1.09 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
41
42
43
44
45
46
47
48
49
package collectionExam;
import java.util.HashMap;
public class HashMapExam {
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<>();
map.put("유재석", 10);
map.put("박명수", 5);
map.put("김종국", 3);
System.out.println(map.size());
System.out.println(map.get("유재석"));
System.out.println(map.get("박명수"));
System.out.println(map.get("김종국"));
if(map.containsKey("서장훈")) {
int num = map.get("서장훈");
num += 1;
map.put("서장훈", num);
}else {
map.put("서장훈", 1);
}
map.remove("유재석");
for (String fantasticyouth : map.keySet()) {
System.out.print(fantasticyouth + " ");
}System.out.println();
for (Integer vksxktmxlrdbtm : map.values()) {
System.out.print(vksxktmxlrdbtm + " ");
}System.out.println();
for (String fantasticyouth : map.keySet()) {
System.out.print(map.get(fantasticyouth) + " ");
}System.out.println();
map.clear();
if(map.isEmpty()) System.out.println(map.size());
}
}