Java HashSet isEmpty() MethodThe 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. SyntaxFollowing is the declaration of isEmpty() method: ParameterThis method does not accept any parameter. ReturnsThe isEmpty() method returns true if this set contains no elements. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: HashSet Elements: [Welcome, To, JavaTpoint] Is the set empty: false Is the set empty: true Example 2Test it NowOutput: Is hash set empty?:- false HashSet Element: [98, 67, 45] Is hash set empty?:- true HashSet Element: [] Example 3Test it NowOutput: student database has 3 names: [Rahul, Mohan, Karan] student database is empty: []
Next TopicHashSet iterator() Method
|