import java.util.HashSet; import java.util.Iterator; public class Main { public static void main(String[] args) { // Creating a HashSet HashSet<String> hashSet = new HashSet<>(); // Adding elements to the HashSet hashSet.add("Apple"); hashSet.add("Banana"); hashSet.add("Orange"); hashSet.add("Grapes"); hashSet.add("Mango"); // Removing an element from the HashSet boolean removed = hashSet.remove("Banana"); System.out.println("Element 'Banana' removed from the HashSet."); // Checking if an element exists in the HashSet boolean contains = hashSet.contains("Orange"); System.out.println("HashSet contains 'Orange': " + contains); // Iterating over the elements in the HashSet using an Iterator System.out.println("Iterating over HashSet elements using Iterator:"); Iterator<String> iterator = hashSet.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } // Clearing the HashSet hashSet.clear(); System.out.println("HashSet cleared. Current size: " + hashSet.size()); } }