Collections in Dart
Definition
Collections are data structures that store multiple values in a single variable. They're essential for managing groups of related data like lists of numbers, lists of names, or key-value pairs.
Three Main Collection Types
**List**
An ordered, indexed collection of items.
Index starts at 0Access items using index: `list[0]`Items can be duplicatedOrder matters`List numbers = [1, 2, 3, 4, 5];
var first = numbers[0]; // 1
`**Map**
A collection of key-value pairs. Use a key to find a value.
Keys are uniqueFast lookup by keyLike a dictionary`Map ages = {
'Alice': 25,
'Bob': 30,
};
`**Set**
An unordered collection of unique items.
No duplicates allowedNo specific orderFast membership testing`Set fruits = {'Apple', 'Banana', 'Orange'};
`Common List Operations
`length`: Number of items`add()`: Add an item`remove()`: Remove an item`contains()`: Check if item exists`forEach()`: Loop through items