DEV Community

Baransel
Baransel

Posted on

Set structures in Dart

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);
}
Enter fullscreen mode Exit fullscreen mode

The output is:

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

Follow my blog for more baransel.dev.

Top comments (0)