Online Java Compiler By
JavaTpoint.com
import java.util.*; public class HashSetIsEmptyExample1 { public static void main(String[] args) { //Creating HashSet Object HashSet
hset = new HashSet
(); //Add elements into the Set hset.add("Welcome"); hset.add("To"); hset.add("JavaTpoint"); //Print the HashSet Values System.out.println("HashSet Elements: "+hset); //Check for the empty set System.out.println("Is the set empty: "+hset.isEmpty()); //Clearing the set and Check for the empty set hset.clear(); System.out.println("Is the set empty: "+hset.isEmpty()); } }
Output