Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/Data Structures/Hashset/HashSetExample.class
Binary file not shown.
32 changes: 32 additions & 0 deletions src/Data Structures/Hashset/HashSetExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.HashSet;

public class HashSetExample {
public static void main(String[] args) {

HashSet<String> set = new HashSet<>();


set.add("Element1");
set.add("Element2");
set.add("Element3");
set.add("Element1");

set.remove("Element2");


System.out.println("Iterating over HashSet using for-each loop:");
for (String element : set) {
System.out.println(element);
}

boolean contains = set.contains("Element3");
System.out.println("HashSet contains 'Element3': " + contains);

int size = set.size();
System.out.println("Size of HashSet: " + size);

set.clear();
System.out.println("Size of HashSet after clear: " + set.size());
}
}