In Dart, collections are objects used to store multiple values in an organized and iterable manner. Dart provides built-in support for various types of collections, including lists, sets, maps, and queues. These collection types offer different characteristics and are suited for different use cases.
List< int> numbers = [1, 2, 3, 4, 5];
List< String> names = ['Alice', 'Bob', 'Charlie'];
Set< int> uniqueNumbers = {1, 2, 3, 4, 5};
Set< String> uniqueNames = {'Alice', 'Bob', 'Charlie'};
Map
Map
import 'dart:collection';
Queue
queue.addAll([1, 2, 3]);
queue.removeFirst();
queue.removeLast();
List< int > numbers = [1, 2, 3, 4, 5];
numbers.forEach((number) => print(number));
Set< String > names = {'Alice', 'Bob', 'Charlie'};
for (var name in names) {
print(name);
}
Map< String, int > ages = {'Alice': 30, 'Bob': 25, 'Charlie': 35};
ages.forEach((key, value) => print('$key is $value years old'));
var constantList = const [1, 2, 3];
var constantSet = const {'Alice', 'Bob', 'Charlie'};
var constantMap = const {'Alice': 30, 'Bob': 25, 'Charlie': 35};