Online Java Compiler By
JavaTpoint.com
import java.util.*; public class HashSetIsEmptyExample2 { public static void main(String[] args) { HashSet
hashSetObject = new HashSet <>(); hashSetObject.add(45); hashSetObject.add(67); hashSetObject.add(98); //Checking whether HashSet is empty boolean b1 = hashSetObject.isEmpty(); System.out.println("Is hash set empty?:- "+b1); System.out.println("HashSet Element: "+hashSetObject); //Clear HashSet hashSetObject.clear(); boolean b2 = hashSetObject.isEmpty(); System.out.println("Is hash set empty?:- "+b2); System.out.println("HashSet Element: "+hashSetObject); } }
Output