Java HashSet.remove(Object o)
Syntax
HashSet.remove(Object o) has the following syntax.
public boolean remove(Object o)
Example
In the following code shows how to use HashSet.remove(Object o) method.
// ww w . j a va2 s .c o m
import java.util.HashSet;
public class Main {
public static void main(String args[]) {
HashSet<String> newset = new HashSet <String> ();
newset.add("Learning");
newset.add("from");
newset.add("java2s.com");
System.out.println("Values before remove: "+newset);
// remove "Easy" from set
boolean isremoved = newset.remove("from");
System.out.println("Return value after remove: "+isremoved);
System.out.println("Values after remove: "+newset);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »