HashSet clear() method in java code example
Example: HashSet clear() method in java
import java.util.HashSet;
public class HashSetClearMethodExample
{
public static void main(String[] args)
{
HashSet<String> hs = new HashSet<String>();
hs.add("Welcome");
hs.add("hello");
hs.add("world");
hs.add("core");
hs.add("java");
System.out.println("HashSet before using clear() method: " + hs);
// HashSet clear() method
hs.clear();
System.out.println("HashSet after using clear() method: " + hs);
}
}