-
-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathHashSetExample.java
More file actions
44 lines (32 loc) · 815 Bytes
/
Copy pathHashSetExample.java
File metadata and controls
44 lines (32 loc) · 815 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
package util;
import java.util.HashSet;
/**
* Created by nikoo28 on 8/6/22 2:14 PM
*/
public class HashSetExample {
public static void main(String[] args) {
// Creating a hashset
HashSet<Integer> myHashSet = new HashSet<>();
// Add some integers
myHashSet.add(4);
myHashSet.add(8);
myHashSet.add(15);
myHashSet.add(16);
// Print
System.out.println(myHashSet);
// Check if 4 is present
if(myHashSet.contains(4))
System.out.println("PRESENT");
else
System.out.println("NOT PRESENT");
// Check if 100 is present
if(myHashSet.contains(100))
System.out.println("PRESENT");
else
System.out.println("NOT PRESENT");
// Delete element
myHashSet.remove(8);
// Print again
System.out.println(myHashSet);
}
}