Dart .contains()
Anonymous contributor
Published May 6, 2024
Contribute to Docs
The .contains() method in Dart checks if a specified element is present in the given queue.
Syntax
bool contains(Object element)
element: It is the object that needs to be checked in the queue.
Example 1
In the following example, the code checks whether the queue contains an element 3 or not:
import 'dart:collection';void main() {var queue = Queue();queue.addAll([1, 2, 3, 4, 5]);print(queue.contains(3));}
The output of the above code is:
true
Example 2
The following example uses the ‘.contains()’ method to check if the name ‘Bob’ is present in the queue:
import 'dart:collection';void main() {var names = Queue<String>();names.addAll(['Alice', 'Bob', 'Charlie', 'David']);print(names.contains('Bob'));}
The output of the above is:
false
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.
Learn Dart on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours