share

Wednesday, 27 May 2015

How To Remove Element of Hashset

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

public class RemoveElement {
   
    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 the specified element from  set
         * if it is present
         */
        hs.remove("php");
       
        System.out.println("After Remove element hashset is ="+hs);
       
    }

}




Output:


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

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

No comments:

Post a Comment