We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 404c837 commit b4e1476Copy full SHA for b4e1476
2 files changed
src/Data Structures/Hashset/HashSetExample.class
1.57 KB
src/Data Structures/Hashset/HashSetExample.java
@@ -0,0 +1,32 @@
1
+import java.util.HashSet;
2
+
3
+public class HashSetExample {
4
+ public static void main(String[] args) {
5
6
+ HashSet<String> set = new HashSet<>();
7
8
9
+ set.add("Element1");
10
+ set.add("Element2");
11
+ set.add("Element3");
12
13
14
+ set.remove("Element2");
15
16
17
+ System.out.println("Iterating over HashSet using for-each loop:");
18
+ for (String element : set) {
19
+ System.out.println(element);
20
+ }
21
22
+ boolean contains = set.contains("Element3");
23
+ System.out.println("HashSet contains 'Element3': " + contains);
24
25
+ int size = set.size();
26
+ System.out.println("Size of HashSet: " + size);
27
28
+ set.clear();
29
+ System.out.println("Size of HashSet after clear: " + set.size());
30
31
+}
32
0 commit comments