Created
April 7, 2020 08:05
-
-
Save tailorvj/9c37caf8cebb26ee12d1f65890ee6b47 to your computer and use it in GitHub Desktop.
Dart example: Iterating through a Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main(){ | |
Map<String, int> scores = {'Bob': 300}; | |
print('Initial state of the scores Map: $scores'); | |
for (var key in ['Bob', 'Rohan', 'Sophena']) { | |
scores.putIfAbsent(key, () => key.length); | |
} | |
for (MapEntry entry in scores.entries){ | |
print('scores[\'${entry.key}\']: ${entry.value}'); | |
} | |
List listOfKeys = scores.keys.toList(); | |
print('list of keys: $listOfKeys'); | |
List listOfValues = scores.values.toList(); | |
print('list of values: $listOfValues'); | |
Map mapFromIterables = Map.fromIterables(listOfKeys, listOfValues); | |
print('map from Iterables: $mapFromIterables'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment