Clear a hash set

void clear()
Removes all of the elements from this set.

  import java.util.HashSet;

public class Main{
    public static void main(String args[]) {
        HashSet<String> hs = new HashSet<String>();

        hs.add("java2s.com");
        hs.add("A");
        hs.add("D");
        hs.add("E");
        hs.add("C");
        hs.add("j a v a2s.com");

        System.out.println(hs);
        
        hs.clear();
        
        System.out.println(hs);
        
    }
}
  

[D, E, j a v a2s.com, A, java2s.com, C]
[]
Home 
  Java Book 
    Collection  

HashSet:
  1. HashSet class
  2. Add element to hash set
  3. Clear a hash set
  4. Clone a hash set
  5. If a hash set contain a certain element
  6. Is this set containing a certain element
  7. Get an iterator from a hash set
  8. Remove an element from hash set
  9. Get the size of a hash set