Showing posts with label remove all element from hashset. Show all posts
Showing posts with label remove all element from hashset. Show all posts

Wednesday, 27 May 2015

How to remove all element from HashSet


import java.util.HashSet;
import java.util.Set;

public class RemoveAll {
   
public static void main(String[] args) {
       
        Set<String> hs = new HashSet<String>();
        hs.add("java");
        hs.add("php");
        hs.add("html");
        hs.add("javascript");
        hs.add("mysql");
       
        //print hashset
        System.out.println("Before Remove element hashset is = "+hs);
       
         /*
          * Removes all of the elements from  set
          */
        hs.clear();
       
        System.out.println("After Remove elements hashset is ="+hs);
       
    }

}






Output:


Before Remove element hashset is = [javascript, php, html, java, mysql]

After Remove elements hashset is =[]