122
Java HashSet isEmpty() Method
The isEmpty() method of Java HashSet class is used to check wheather HashSet contains an element or not. It returns true if the set contains element, otherwise returns false.
Syntax
Following is the declaration of isEmpty() method:
Parameter
This method does not accept any parameter.
Returns
The isEmpty() method returns true if this set contains no elements.
Exceptions
NA
Compatibility Version
Java 1.2 and above
Example 1
Output:
HashSet Elements: [Welcome, To, TutorAspire ] Is the set empty: false Is the set empty: true
Example 2
Output:
Is hash set empty?:- false HashSet Element: [98, 67, 45] Is hash set empty?:- true HashSet Element: []
Example 3
Output:
student database has 3 names: [Rahul, Mohan, Karan] student database is empty: []
Next TopicHashSet iterator() Method