Check if a particular element exists in LinkedHashSet - Java Collection Framework

Java examples for Collection Framework:LinkedHashSet

Description

Check if a particular element exists in LinkedHashSet

Demo Code


import java.util.LinkedHashSet;
 
public class Main {
 
  public static void main(String[] args) {
    LinkedHashSet lhashSet = new LinkedHashSet();
   /* w  w  w  .  j  a  v  a 2  s.  c  o m*/
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
 
    boolean blnExists = lhashSet.contains(new Integer("3"));
    System.out.println("3 exists in LinkedHashSet ? : " + blnExists);
  }
}

Result


Related Tutorials