-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDemoMap.java
More file actions
36 lines (27 loc) · 1.08 KB
/
Copy pathDemoMap.java
File metadata and controls
36 lines (27 loc) · 1.08 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
package KienTrucCollections;
import java.util.HashMap;
import java.util.Map;
public class DemoMap {
public static void main(String[] args) {
Map<String, String> hashMap = new HashMap<String, String>();
hashMap.put("Windows", "2000");
hashMap.put("Windows", "XP");
hashMap.put("Language2", "Java");
hashMap.put("Language1", ".Net");
hashMap.put("Windows", "Window 11");
System.out.println("Các phần tử của Map");
System.out.print("\t" + hashMap);
Map<String, String> dataUser = new HashMap<String, String>();
dataUser.put("name", "Ngọc Ánh");
dataUser.put("age", "25");
dataUser.put("phone", "0123456789");
dataUser.put("address", "HN");
System.out.println("");
//Truy xuất giá trị theo từng key
System.out.println(dataUser.get("name"));
//Get hết giá trị của key và value
for (Map.Entry<String, String> entry : dataUser.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
}