Answers for "HashSet isEmpty() method in java"

1

HashSet isEmpty() method in java

import java.util.HashSet;
public class HashSetIsEmptyMethodExample
{
   public static void main(String[] args)
   {
      HashSet<String> hs = new HashSet<String>();
      hs.add("Welcome");
      hs.add("hello");
      hs.add("world");
      hs.add("core");
      hs.add("java");
      System.out.println("HashSet before using isEmpty() method: " + hs);
      // check if HashSet is empty
      System.out.println("Is the HashSet empty: " + hs.isEmpty());
      // clear HashSet using clear() method
      hs.clear();
      // again check if HashSet is empty
      System.out.println("Is the HashSet empty: " + hs.isEmpty());
   }
}
Posted by: Guest on October-28-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language