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]
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