kota's memex

A set in Dart is an unordered collection of unique items. Dart support for sets is provided by set literals and the Set type. The syntax is similar to lists.

var halogens = {'fluorine', 'chlorine', 'bromine', 'iodine', 'astatine'};

literal

To create an empty set, use {} preceded by a type argument, or assign {} to a variable of type Set:

var names = <String>{};
// Set<String> names = {}; // This works, too.
// var names = {}; // Creates a map, not a set.

Set or map? The syntax for map literals is similar to that for set literals. Because map literals came first, {} defaults to the Map type. If you forget the type annotation on {} or the variable it’s assigned to, then Dart creates an object of type Map<dynamic, dynamic>.

add / length

var elements = <String>{};
elements.add('fluorine');
elements.addAll(halogens);