Interview frequency: …
Short answer
List for ordering and index access, Set for unique values, and Map for accessing a value by a key.
Explanation
Choosing the collection expresses the shape of the data and the rules you need (ordering, uniqueness, or mapping a key to a value). A List preserves element order and may contain duplicates, a Set prevents duplicates and suits membership checks, and a Map associates a key with a value, and keys must be suitable for comparison. Do not choose the type just because it is the most common.
Code example
final names = <String>["Ali", "Mona"];
final tags = <String>{"flutter", "dart"};
final scores = <String, int>{"Ali": 90};Common mistakes
- Using a List and then doing a linear search for a value that should be unique.
- Forgetting that a Map does not behave sensibly with mutable keys.