Java HashSet clear() MethodThe clear() method of Java HashSet class is used to removes all of the elements from this set. SyntaxFollowing is the declaration of clear() method: ParameterThis method does not accept any parameter. ReturnsThe clear() method does not return any value. Exceptions:NA Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: Hash set Elements: [DFC, SSSIT, JTP] Hash set elements after clear: [] Example 2Test it NowOutput: Hash set Elements: [151, 121, 111] Hash set elements after clear: [] Example 3Test it NowOutput: Size of the HashSet: 4 Elements of the HashSet before clear: Google Twitter Instagram Facebook Elements of the HashSet after clear: Size of the hashset: 0
Next TopicHashSet clone() Method
|