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,

  1. We create a Runes object runes with the string 'ABC'.
  2. We get an iterator for the runes using the iterator property.
  3. We use a while loop to iterate over the elements using moveNext() and print each element using current.

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,

  1. We create a Runes object runes with the emoji '🚀'.
  2. We get an iterator for the runes using the iterator property.
  3. We use a while loop to iterate over the elements using moveNext() and print each element using current.

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.