Working with Maps
Get introduced to some of the properties and methods of a map in Dart.
Just like lists and sets, maps are objects that have associated properties and methods. Let’s take a look at some of them below.
Adding Key-value pairs
To add a new key-value pair to a map that has already been declared, use the following syntax:
Press + to interact
mapName[key]=value
Let’s add some key-value pairs to the numbers
map we have declared in the widget below.
Press + to interact
main() {var numbers = Map<int, String>();numbers[1] = 'one';numbers[2] = 'two';numbers[3] = 'three';print(numbers);}
In the code snippet above, we added 3 key-value pairs to numbers
.
Finding the number of pairs in a map
Just as we ...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy