Checking an element exist in set

To check an element exist in a set, use the contains() method.

The contains method takes only one parameter and checks if that value is in the set.

Loading...

In the above example:

  • The variable names is a set of strings with predefined values.
  • The contains() method accept an input parameter, a value.
  • Thecontains() method return a boolean value true or false based on whether the input value exist or not.

Try It Yourself

Loading...