-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoCollectionSet.java
More file actions
43 lines (35 loc) · 1.18 KB
/
DemoCollectionSet.java
File metadata and controls
43 lines (35 loc) · 1.18 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
package DemoCollections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class DemoCollectionSet {
public static void main(String[] args) {
//Khai báo kiểu dữ liệu Set
//không lưu được dữ liệu trùng lặp
Set<String> menu = new HashSet<>();
//Thêm dữ liệu
menu.add("Project");
menu.add("Dashboard");
menu.add("Customer");
menu.add("Tasks");
menu.add("Sales");
menu.add("Project");
System.out.println(menu.contains("Tasks12345"));
menu.remove("Sales");
System.out.println(menu.size());
System.out.println("Các phần tử của Set");
System.out.print("\t" + menu + "\n");
System.out.println("\n=======================");
//Duyệt giá trị trong SET
// Show set through Iterator
Iterator<String> itr = menu.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
System.out.println("\n=======================");
// Show set through for-each
for (String obj : menu) {
System.out.println(obj);
}
}
}