Input
Output
import java.util.HashSet; public class HashSetExample { public static void main(String[] args) { HashSet colors = new HashSet<>(); // Add elements colors.add("Red"); colors.add("Green"); colors.add("Blue"); colors.add("Green"); // Duplicate // Display the set System.out.println("HashSet: " + colors); // Check existence if (colors.contains("Blue")) { System.out.println("Blue is in the set."); } // Remove an item colors.remove("Red"); // Print after removal System.out.println("Updated HashSet: " + colors); // Clear the set colors.clear(); // Check if empty System.out.println("Is the set empty? " + colors.isEmpty()); } }