Skip to main content

Data Structures in Dart

Collection literals

Dart has built-in support for lists, maps, and sets. You can create them using literals:

final aListOfStrings = ['one', 'two', 'three']; /// final aListOfInts = <int>[];

final aSetOfStrings = {'one', 'two', 'three'}; /// final aSetOfInts = <int>{};

final aMapOfStringsToInts = { /// final aMapOfIntToDouble = <int, double>{};
'one': 1,
'two': 2,
'three': 3,
};

Only to know, Not to use it in practice: in place of final we can use Dart’s type inference: List<String>, Set<String> & Map<String, int>.