D
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

AspectOperationList / Set / Map
Access by indexList: O(1)Set: N/A, Map: O(1) by key
Membership checkList: O(n)Set/Map key: O(1)
InsertionList end: O(1), middle: O(n)Set/Map: O(1) avg
DeletionList: O(n)Set/Map: O(1) avg
OrderingList: preservedSet/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