How to Check If a Collection Contains an Item

Need to know whether a collection contains a specific item?

Use Contains.

How to Check If a Collection Contains an Item

Common examples:

  • Check whether a list contains a value
  • Check whether a set contains an item
  • Use the result in an if statement
  • Continue when the item exists
  • Handle the case when it doesn't

Contains returns true when the collection contains the specified item and false when it doesn't.

How do you check whether something exists in a collection?