remove in�  Java HashSet Example

remove in�  Java HashSet Example


Posted in : Java Posted on : November 25, 2010 at 6:16 PM Comments : [ 0 ]

This Java Example shows how to remove specific elements which exists in HashSet.

remove in  Java HashSet Example

This Java Example shows how to remove specific elements which exists in HashSet. To remove elements exists in HashSetWe use remove() method of HashSet class.  It removes the specified element stored in the specified object within the collection.

Example:- RemoveInHashSet.java

package devmanuals.com;

import java.util.*;

public class RemoveInHashSet {
	public static void main(String[] args) {

		HashSet hst = new HashSet();
		hst.add("Gyan");
		hst.add("Rohit");
		hst.add("Anand");
		hst.add("Arunesh");
		System.out.println("The Elements are: " + hst);
		boolean bl = hst.remove("Gyan");
		boolean b2 = hst.contains("Gyan");
		System.out.println("Is Gyan exists? :" + b2);
		System.out.println("The Elements are: " + hst);

	}
}

Output:-

The Elements are: [Rohit, Gyan, Arunesh, Anand] 

Is Gyan exists? :  false 

The Elements are: [Rohit, Arunesh, Anand]

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics