AbstractSet contains() method in Java with Example
The contains() method of Java AbstractSet is used to check whether an element is present in a set or not. It takes the element as a parameter and returns True if the element is present in the set.
public boolean contains(Object element)
Parameters: The parameter element is of type set. This parameter refers to the element whose occurrence is needed to be checked in the set.
Return Value: The method returns a boolean value. It returns True if the element is present in the set otherwise it returns False.
Below programs illustrate the AbstractSet.contains() method:
AbstractSet: [10, 20, Geeks, for] Does the set contains 'Hello': false Does the set contains '20': true Does the set contains 'Geeks': true
AbstractSet:[10, 20, 30, 40, 50] Does the set contains '10': true Does the set contains '50': true Does the set contains '100': 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.