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
Java Book
Collection
LinkedHashSet:
- LinkedHashSet class
- Check if an element exists in LinkedHashSet using contains method
- Copy all elements of LinkedHashSet to an Object Array