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
Home 
  Java Book 
    Collection  

LinkedHashSet:
  1. LinkedHashSet class
  2. Check if an element exists in LinkedHashSet using contains method
  3. Copy all elements of LinkedHashSet to an Object Array