Iterator<E> class

An interface for getting items, one at a time, from an object.

The for-in construct transparently uses Iterator to test for the end of the iteration, and to get each item (or element).

If the object iterated over is changed during the iteration, the behavior is unspecified.

The Iterator is initially positioned before the first element. Before accessing the first element the iterator must thus be advanced using moveNext to point to the first element. If no element is left, then moveNext returns false, and all further calls to moveNext will also return false.

The current value must not be accessed before calling moveNext or after a call to moveNext has returned false.

A typical usage of an Iterator looks as follows:

var it = obj.iterator;
while (it.moveNext()) {
  use(it.current);
}

See also: Iteration in the library tour

Implementers

Constructors

Iterator()

Properties

current → E
read-only
The current element. [...]
hashCodeint
read-only, inherited
The hash code for this object. [...]
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.

Methods

moveNext() → bool
Advances the iterator to the next element of the iteration. [...]
noSuchMethod(Invocation invocation) → dynamic
inherited
Invoked when a non-existent method or property is accessed. [...]
toString() → String
inherited
A string representation of this object. [...]

Operators

operator ==(Object other) → bool
inherited
The equality operator. [...]

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-core/Iterator-class.html