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 |
[ 0 ] Comments