How to check the existence of particular element in the LinkedHashSet?
Previous | Home | Next |
This example will shows us how to check the existence of the element in the LinkedHashSet.
To check the existence of particular element in the LinkedHashSet we use contain() . it check the availability of element in the Set.
public boolean contains(Object o)
will return the answer in boolean value i.e. true/false
Simply calls the contain() along with the object of LinkedHashSet and pass it to blnExists object.
/**
*
*/
package Example;
import java.util.LinkedHashSet;
import java .util.Iterator;
/**
* @author R4R
*
*/
public class ExistenceElements {
/**
* @param args
*/
public static void main(String[] args) {
LinkedHashSet Lhst = new LinkedHashSet();
Lhst.add("10");
Lhst.add("11");
Lhst.add("12");
Lhst.add("13");
Lhst.add("14");
Lhst.add("15");
Lhst.add("16");
System.out.println(" The LinkedHashSet contains the elements :"+Lhst);
Lhst.size();
System.out.println(" The size of the LinkedHashSet is:" + Lhst.size());
boolean blnExists=Lhst.contains("15");
System.out.println("The element is exists in the set is :"+blnExists);
// TODO Auto-generated method stub
}
}
The LinkedHashSet contains the elements :[10, 11, 12, 13, 14, 15, 16]
The size of the LinkedHashSet is:7
The element is exists in the set is :true
Previous | Home | Next |