Set structure is a type of list that we use to hold multiple data like List. It has the same features as List.

Unlike List;

  • It is unordered.
  • 2 identical elements cannot be found. (unique)

You can see the example below:

Set<String> names = Set();
List<String> words = [];

main() {
  names.add('Baran');
  names.add('Baran');
  names.add('Baran');
  names.add('Batuhan');
  words.add('Turgut');
  words.add('Turgut');
  words.add('Berk');
  words.add('Ege');

  print("Data defined by Set;");
  print(names);
  print("Data defined by List;");
  print(words);
}

The output is:

Data defined by Set;
{Baran, Batuhan}
Data defined by List;
[Turgut, Turgut, Berk, Ege]