-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapMain1.java
More file actions
41 lines (32 loc) · 1.29 KB
/
Copy pathMapMain1.java
File metadata and controls
41 lines (32 loc) · 1.29 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
package collection.map;
import java.util.*;
public class MapMain1 {
public static void main(String[] args) {
Map<String, Integer> studentMap = new HashMap<>();
studentMap.put("studentA", 90);
studentMap.put("studentB", 80);
studentMap.put("studentC", 70);
studentMap.put("studentD", 60);
System.out.println("studentMap = " + studentMap);
Integer result = studentMap.get("studentD");
System.out.println("result = " + result);
System.out.println("KeySet 활용");
Set<String> key = studentMap.keySet();
for (String s : key) {
Integer score = studentMap.get(s);
System.out.println("key = " + s + ", value = " + score);
}
System.out.println("EntrySet 활용");
Set<Map.Entry<String, Integer>> entries = studentMap.entrySet();
for (Map.Entry<String, Integer> entry : entries) {
String student = entry.getKey();
Integer value = entry.getValue();
System.out.println("student = " + student + ", value = " + value);
}
System.out.println("Values 활용");
Collection<Integer> values = studentMap.values();
for (Integer value : values) {
System.out.println("value = " + value);
}
}
}