.contains()
Anonymous contributor
Published Feb 14, 2024
Contribute to Docs
The .contains()
method determines whether a specified element is present in a list. It returns a Boolean value of true
if the element is found in the list and false
if it happens otherwise.
Syntax
list.contains(element)
list
: The name of the list that needs to be searched.element
: The element that needs to be searched.
Example
In this example, the .contains()
method is used to check if the string banana
is present in the fruits
list:
void main() {List<String> fruits = ['apple', 'banana', 'orange'];// The .contains() method searches for the element 'banana' in the 'fruits' listbool containsBanana = fruits.contains('banana');print(containsBanana);}
Here is the output for the above code:
true
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.