Dart Set

Dart Set

What is sets?

A set in Dart is an unordered collection of unique items. Dart support for sets is provided by set literals and the set type.

Example:

void main() {
  List<int> numbers = [1, 2, 3, 4, 1, 2, 5, 6, 3];

  Set<int> uniqueNumbers = Set<int>.from(numbers);

  List<int> uniqueList = uniqueNumbers.toList();

  print("Original list: $numbers");
  print("List after removing duplicates: $uniqueList");
  print(uniqueNumbers);
}

Output:

Original list: [1, 2, 3, 4, 1, 2, 5, 6, 3]
List after removing duplicates: [1, 2, 3, 4, 5, 6]
{1, 2, 3, 4, 5, 6}

Exited.