Remove specified element from HashSet in Java
Description
The following code shows how to remove specified element from HashSet.
Example
/*from w w w . ja v a 2s. c o m*/
import java.util.HashSet;
public class Main {
public static void main(String[] args) {
HashSet<Integer> hSet = new HashSet<Integer>();
hSet.add(new Integer("1"));
hSet.add(new Integer("2"));
hSet.add(new Integer("3"));
System.out.println(hSet);
boolean blnRemoved = hSet.remove(new Integer("2"));
System.out.println(blnRemoved);
System.out.println(hSet);
}
}
The code above generates the following result.