Checking if Element Exists in LinkedHashSet in Java
The Java.util.LinkedHashSet.contains() method is used to check whether a specific element is present in the LinkedHashSet or not. So basically it is used to check if a Set contains any particular element. The contains a method of the LinkedHashSet class returns true if the specified element is found in the LinkedHashSet object.
Given List: [1, 2, 3, 4] Input : FirstSearch = 1, SecondSearch = 6 Output: True False
Return Type: If the element found in the then it returns true, else false.
Parameters: The parameter element is of the type of LinkedHashSet. This is the element that needs to be tested if it is present in the set or not.
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.