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 168 views
1 answer 186 views
1 answer 147 views
1 answer 171 views
1 answer 171 views
2 answers 151 views
1 answer 176 views
...