Dart does not support array unlike other programming. Dart collections can be used to replicate data structure like an array. The dart:core library and other classes enable Collection support in Dart scripts. Dart collections can be classified as-
Dart Collection | Description |
---|---|
Sets | Sets are the fundamental data structures which represents a collection of objects in which each object can occur only once. |
Maps | The Map object is a simple key/value pair. Keys and values in map may be of any datatype.A map is a dynamic collection. |
Lists | List are the ordered collection of objects. Theu play cruical role in dart applications. |
The iterator class from the dart:core library enables easy collection traversal. Every collection has an iterator property. This property return oan iterator that points to the objects in the collection. Example
import 'dart:collection';
void main(){
Set<int> numbers = {1, 2, 3, 4, 5,6,7};
for (int number in numbers) {
print(number);
}
}
The output of the above example:-
1
2
3
4
5
6
7