LinkedHashSet contains() method in Java with Examples
The contains() method of java.util.LinkedHashSet class is used to return true if this set contains the specified element otherwise false.
public boolean contains(Object o)
Parameters: This method takes element o as parameter whose presence in this set is to be tested.
Return Value: This method returns true if this set contains the specified element.
Below are the examples to illustrate the contains() method.
LinkedHashSet: [A, B, C] Is the element 'C' present: true
LinkedHashSet: [10, 20, 30] Is the element '25' present: false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.