-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhashsetFunctions.java
More file actions
31 lines (26 loc) · 933 Bytes
/
hashsetFunctions.java
File metadata and controls
31 lines (26 loc) · 933 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
import java.util.*;
public class hashsetFunctions {
public static void main(String[] args) {
HashSet<String> set = new HashSet<>();
// TO ADD VALUE IN HASH SER
set.add("Anand");
set.add("Aman");
set.add("Amitosh");
set.add("Azad");
System.out.println("Original hash value");
for (String key : set) {
System.out.println(key + " ");
}
System.out.println("Operations on hashsets");
// TO CHECK THE VALUE PRESENT IN HASHSET OR NOT
System.out.println(set.contains("Anand"));
// TO GET THE SIZE OF THE HASH SET
System.out.println(set.size());
// TO REMOVE THE VALUE FROM HASHSET
System.out.println(set.remove("Amitosh"));
// ITERATION OF HASH SET
for (String key : set) {
System.out.println(key + " ");
}
}
}