Dart LanguageIntermediate30 XP3 min read
How do Dart's List, Set, and Map compare in performance?
TL;DR: List: O(1) index access, O(n) search; Set/Map (hash-based): O(1) lookup/insert/delete on average. Use Set when you need unique items and O(1) membership tests; Map for key-value lookups.
Full Answer
| Aspect | Operation | List / Set / Map |
|---|---|---|
| Access by index | List: O(1) | Set: N/A, Map: O(1) by key |
| Membership check | List: O(n) | Set/Map key: O(1) |
| Insertion | List end: O(1), middle: O(n) | Set/Map: O(1) avg |
| Deletion | List: O(n) | Set/Map: O(1) avg |
| Ordering | List: preserved | Set/Map: insertion order (LinkedHash*) |
Interview Tip
💡
Dart's default Set and Map are LinkedHashSet and LinkedHashMap respectively — they maintain insertion order, unlike Java's HashSet. This is a common interview distinction.
#list#set#map#performance#complexity#collections