1import java.util.HashSet;
2public class HashSetIsEmptyMethodExample
3{
4 public static void main(String[] args)
5 {
6 HashSet<String> hs = new HashSet<String>();
7 hs.add("Welcome");
8 hs.add("hello");
9 hs.add("world");
10 hs.add("core");
11 hs.add("java");
12 System.out.println("HashSet before using isEmpty() method: " + hs);
13 // check if HashSet is empty
14 System.out.println("Is the HashSet empty: " + hs.isEmpty());
15 // clear HashSet using clear() method
16 hs.clear();
17 // again check if HashSet is empty
18 System.out.println("Is the HashSet empty: " + hs.isEmpty());
19 }
20}