How to create key value dictionary in Dart

1 Answer

0 votes
void main() {
	var dict = {
		'a': 'dart',
		'b': 'rust',
		'c': 'c',
		'd': 'c++',
		'e': 'java'
	};
	
	print('Key Value:');
	dict.forEach((key, value) => print('$key - $value'));
	
	print('\nKeys:');
	dict.keys.forEach((key) => print(key));
	
	print('\nValues:');
	dict.values.forEach((value) => print(value));
}





/*
run:

Key Value:
a - dart
b - rust
c - c
d - c++
e - java

Keys:
a
b
c
d
e

Values:
dart
rust
c
c++
java

*/

 



answered Dec 10, 2022 by avibootz

Related questions

2 answers 185 views
1 answer 201 views
1 answer 154 views
1 answer 181 views
1 answer 184 views
2 answers 165 views
1 answer 187 views
...