Dart Runes iterator
Syntax & Examples
Runes.iterator property
The `iterator` property of the `Rune` class returns a new Iterator that allows iterating the elements of the Rune, which can represent characters, emojis, or Unicode code points.
Syntax of Runes.iterator
The syntax of Runes.iterator property is:
RuneIterator iterator This iterator property of Runes returns a new Iterator that allows iterating the elements of this Iterable.
Return Type
Runes.iterator returns value of type RuneIterator.
✐ Examples
1 Iterating over a rune representing a character
In this example,
- We create a Runes object
runeswith the string 'ABC'. - We get an iterator for the runes using the
iteratorproperty. - We use a while loop to iterate over the elements using
moveNext()and print each element usingcurrent.
Dart Program
void main() {
Runes runes = Runes('ABC');
var iterator = runes.iterator;
while (iterator.moveNext()) {
print(iterator.current);
}
}Output
65 66 67
2 Iterating over a rune representing an emoji
In this example,
- We create a Runes object
runeswith the emoji '🚀'. - We get an iterator for the runes using the
iteratorproperty. - We use a while loop to iterate over the elements using
moveNext()and print each element usingcurrent.
Dart Program
void main() {
Runes runes = Runes('🚀');
var iterator = runes.iterator;
while (iterator.moveNext()) {
print(iterator.current);
}
}Output
128640
Summary
In this Dart tutorial, we learned about iterator property of Runes: the syntax and few working examples with output and detailed explanation for each example.