Dart Runes any()
Syntax & Examples
Runes.any() method
The `any` method in Dart checks whether any element of this iterable satisfies a given test function.
Syntax of Runes.any()
The syntax of Runes.any() method is:
bool any(bool test(int element))
This any() method of Runes checks whether any element of this iterable satisfies test
.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
test | required | A function that takes an integer element as input and returns a boolean value indicating whether the element satisfies the test. |
Return Type
Runes.any() returns value of type bool
.
✐ Examples
1 Check for uppercase characters
In this example,
- We create a sequence of Unicode code points
runes
from the string 'Hello'. - We use the
any
method with a test function to check if there are any uppercase characters. - We then print the result to standard output.
Dart Program
void main() {
Runes runes = Runes('Hello');
bool hasUpperCase = runes.any((element) => element >= 65 && element <= 90);
print('Does sequence have uppercase characters? $hasUpperCase');
}
Output
Does sequence have uppercase characters? true
2 Check for space character
In this example,
- We create a sequence of Unicode code points
emojis
from the string '👋🏽🚀🌟'. - We use the
any
method with a test function to check if there is any space character. - We then print the result to standard output.
Dart Program
void main() {
Runes emojis = Runes('👋🏽🚀🌟');
bool hasSpace = emojis.any((element) => element == 32);
print('Does emoji sequence have space character? $hasSpace');
}
Output
Does emoji sequence have space character? false
3 Check for even number
In this example,
- We create a sequence of Unicode code points
numbers
from the string '12345'. - We use the
any
method with a test function to check if there are any even numbers. - We then print the result to standard output.
Dart Program
void main() {
Runes numbers = Runes('12345');
bool hasEvenNumber = numbers.any((element) => element % 2 == 0);
print('Does number sequence have even number? $hasEvenNumber');
}
Output
Does number sequence have even number? true
Summary
In this Dart tutorial, we learned about any() method of Runes: the syntax and few working examples with output and detailed explanation for each example.