Check value is exists In Java HashSet Example

Check value is exists In Java HashSet Example


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

This Java Example shows how to check whether a particular value exists in HashSet or not.

Check value is exists In Java HashSet Example

This Java Example shows how to check whether a particular value exists in HashSet or not. To check whether a particular value exists in HashSet We use boolean contains(Object value) method of HashSet class.  It returns true if a specified object is an element within the collection otherwise false.

Example:- CheckValueInHashSet.java

package devmanuals.com;

import java.util.*;

public class CheckValueInHashSet {

	public static void main(String[] args) {

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

	}
}

Output:-

Is Gyan exists? :true

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics