Home Tutorial Java Core Hashset How to remove specific element from Hashset.

 
 

How to remove specific element from Hashset.
Posted on: April 4, 2011 at 12:00 AM
Advertisement
How to remove specific element from Hashset.

How to remove specific element from Hashset.

In this  exmple, you will see how to remove specific element from hashset.
The HashSet class provides a method called remove. It removes a elements from set.

Code

HashSetRemoveElement.java

package net.roseindia;

import java.util.HashSet;

public class HashSetRemoveElement {

public static void main(String[] arg) {

HashSet obHashSet = new HashSet();

obHashSet.add("Bharat");

obHashSet.add("Gyan");

obHashSet.add("Ankita");

obHashSet.add("vrishti");

System.out.println("Element before remove method : " + obHashSet);

obHashSet.remove("vrishti");

System.out.println("Element after remove method : " + obHashSet);

 } }

Output :

Element before remove method : [Gyan, Ankita, vrishti, Bharat]

Element after remove method : [Gyan, Ankita, Bharat]

Advertisement

Related Tags for How to remove specific element from Hashset.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 4, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com