Check if an element exists in LinkedHashSet using contains method

 

import java.util.LinkedHashSet;

public class Main {
  public static void main(String[] args) {
 
    LinkedHashSet linkedHashSet = new LinkedHashSet();

    linkedHashSet.add("a value");
    linkedHashSet.add("java 2s.com");
    linkedHashSet.add("another value");
    
    
    System.out.println(linkedHashSet.contains("a value"));
    System.out.println(linkedHashSet.contains("the third value"));

  }
}

 

The output:


true
false
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.