Search⌘ K

Generic Collections- Set & Map

Explore how to implement Dart generics by working with Set and Map collections. Learn to add and iterate items while maintaining type safety to avoid common errors. This lesson will help you write reusable and reliable code using generic collections in Dart.

Let’s check out the type safe implementations for two of the Dart’s collection literals: Set & Map.

Set

In a Set collection, each object can only occur once.

Creating Set

A set theSet of the String data type is constructed using the parameterized constructor Set<String>.from({"1"}).

Set<String> theSet = Set<String>.from({"1"});

Same data type item

Two more items of the same type String are added to the set theSet, iterating over the set theSet ...