How to search a particular element exist in hashset
Previous | Home | Next |
This example will shows how to check the particular element is exists in the java Hashset.
Using contain method we will check the presence of particular element in the javaHashset.
Boolean contain method of Hashset class is used to check whether the particular element exist or not in the Hashset .
Counts method check the existence of element if it founds it returns true otherwise returns false.
package Example;
import java.util.HashSet;
public class HashSetExample {
public static void main(String[] args) {
HashSet hSet = new HashSet();
hSet.add(new Integer("8"));
hSet.add(new Integer("15"));
hSet.add(new Integer("13"));
hSet.add(new Integer("7"));
boolean blnExists = hSet.contains(new Integer("2"));
System.out.println(" exists in HashSet : " + blnExists);
}
}
exists in HashSet : false
Previous | Home | Next |