forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashSetExample.java
More file actions
57 lines (46 loc) · 918 Bytes
/
HashSetExample.java
File metadata and controls
57 lines (46 loc) · 918 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.examplehub.basics.set;
import java.util.HashSet;
public class HashSetExample {
public static void main(String[] args) {
HashSet<String> hashSet = new HashSet<>();
hashSet.add("Java");
hashSet.add("Python");
hashSet.add("HTML");
hashSet.add("C");
/*
* [Java, C, HTML, Python]
*/
System.out.println(hashSet);
hashSet.add("Java");
/*
* [Java, C, HTML, Python]
*/
System.out.println(hashSet);
/*
* Java
* C
* HTML
* Python
*/
for (String item : hashSet) {
System.out.println(item);
}
/*
* true
*/
System.out.println(hashSet.contains("Java"));
/*
* true
*/
System.out.println(hashSet.remove("Java"));
/*
* [C, HTML, Python]
*/
System.out.println(hashSet);
hashSet.clear();
/*
* []
*/
System.out.println(hashSet);
}
}