clear(): This method is available in java.util.LinkedHashSet class of Java.
Syntax:
void java.util.HashSet.clear()
This method removes all of the elements from this set.
Note: The set will be empty after this call returns.
Parameters: NA
Returns: NA
Exceptions: NA
Approach
Java
import java.util.LinkedHashSet;public class LinkedHashSetclear {public static void main(String[] args) {LinkedHashSet<String> linkedHashSet =new LinkedHashSet<>();linkedHashSet.add("Hello");linkedHashSet.clear();System.out.println(linkedHashSet);}}
Output:
[]
No comments:
Post a Comment