Online Java Compiler By
JavaTpoint.com
import java.util.*; public class HashSetRemoveExample2 { public static void main(String[] args) { HashSet
hashSetObject = new HashSet <>(); hashSetObject.add(45); hashSetObject.add(67); hashSetObject.add(98); hashSetObject.add(24); //Display HashSet System.out.println("HashSet: " + hashSetObject); //Remove elements using remove() method hashSetObject.remove(98); hashSetObject.remove(24); //Displaying the HashSet after removal System.out.println("HashSet after removing elements: " + hashSetObject); } }
Output