hashset isempty 28 29 method in java

Solutions on MaxInterview for hashset isempty 28 29 method in java by the best coders in the world

showing results for - "hashset isempty 28 29 method in java"
Jacob
08 Jul 2018
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}