Version note: Although the Set type has always been a core part of Dart, set literals were introduced in Dart 2.2.

    Here is a simple Dart set, created using a set literal:

    To create an empty set, use {} preceded by a type argument,or assign {} to a variable of type 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>.

    Use .length to get the number of items in the set:

    To create a set that’s a compile-time constant,add const before the set literal:

    For more information about sets, see andSets.