hashset clear 28 29 method in java

Solutions on MaxInterview for hashset clear 28 29 method in java by the best coders in the world

showing results for - "hashset clear 28 29 method in java"
Debbie
03 Nov 2020
1import java.util.HashSet;
2public class HashSetClearMethodExample
3{
4   public static void main(String[] args)
5   {
6      HashSet<String> hs = new HashSet<String>();
7      hs.add("Welcome");
8      hs.add("hello");
9      hs.add("world");
10      hs.add("core");
11      hs.add("java");
12      System.out.println("HashSet before using clear() method: " + hs);
13      // HashSet clear() method
14      hs.clear();
15      System.out.println("HashSet after using clear() method: " + hs);
16   }
17}