Dart Runes contains()
Syntax & Examples
Runes.contains() method
The `contains` method in Dart checks if the collection contains an element equal to the specified element.
Syntax of Runes.contains()
The syntax of Runes.contains() method is:
bool contains(Object element)
This contains() method of Runes returns true if the collection contains an element equal to element
.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
element | required | The element to check for in the collection. |
Return Type
Runes.contains() returns value of type bool
.
✐ Examples
1 Check for 'e' in sequence
In this example,
- We create a sequence of Unicode code points
runes
from the string 'Hello'. - We use the
contains
method to check if the sequence contains the Unicode code point for 'e'. - We then print the result to standard output.
Dart Program
void main() {
Runes runes = Runes('Hello');
bool containsE = runes.contains(101);
print('Does sequence contain the Unicode code point for \'e\'? $containsE');
}
Output
Does sequence contain the Unicode code point for 'e'? true
2 Check for rocket emoji in sequence
In this example,
- We create a sequence of Unicode code points
emojis
from the string '👋🏽🚀🌟'. - We use the
contains
method to check if the sequence contains the Unicode code point for rocket emoji. - We then print the result to standard output.
Dart Program
void main() {
Runes emojis = Runes('👋🏽🚀🌟');
bool containsRocket = emojis.contains(127937);
print('Does emoji sequence contain the Unicode code point for rocket? $containsRocket');
}
Output
Does emoji sequence contain the Unicode code point for rocket? true
3 Check for '3' in sequence
In this example,
- We create a sequence of Unicode code points
numbers
from the string '12345'. - We use the
contains
method to check if the sequence contains the Unicode code point for '3'. - We then print the result to standard output.
Dart Program
void main() {
Runes numbers = Runes('12345');
bool containsThree = numbers.contains(51);
print('Does number sequence contain the Unicode code point for \'3\'? $containsThree');
}
Output
Does number sequence contain the Unicode code point for '3'? true
Summary
In this Dart tutorial, we learned about contains() method of Runes: the syntax and few working examples with output and detailed explanation for each example.