All programming languages possess some mechanism to organize data. We've already covered the most common way – objects. These class-based structures allow you, the programmer, to define how you want to model your data and manipulate it with methods.
If you want to model groups of similar data, collections are your solution. A collection contains a group of elements. There are many types of collections in Dart, but we are going to focus on the three most popular ones: List, Map, and Set.
- Lists are linear collections where the order of the elements is maintained.
- Maps are a non-linear collection of values that can be accessed by a unique key.
- Sets are a non-linear collection of unique values where the order is not maintained.
These three main types of collections can be found in almost every programming language, but sometimes by a different name. If Dart is not your first programming language, then this matrix should help you correlate collections to equivalent concepts in other languages:
Dart | Java | Swift | JavaScript |
List | ArrayList | Array | Array |
Map | HashMap | Dictionary | Object |
Set | HashSet | Set | Set |