import java.util.HashSet;Output:
public class HashSetremove{
public static void main(String[] args) {
HashSet< String> hashset = new HashSet< String> ();
hashset.add("v1");
hashset.add("v2");
hashset.add("v3");
hashset.add("v4");
hashset.add("v5");
System.out.println("HashSet before removal: "+hashset);
Object e = "v2";
boolean b = hashset.remove("v2");
System.out.println("the "+e+" element removed: "+b);
System.out.println("HashSet after removing "+e+": "+hashset);
}
}
HashSet before removal: [v1, v5, v4, v3, v2]
v2 item removed: true
HashSet after v2 removal: [v1, v5, v4, v3]
Please disable your ad blocker and refresh the window to use this website.