Dart Map()
Syntax & Examples
Syntax of Map
The syntax of Map.Map constructor is:
Map()
This Map constructor of Map creates an empty LinkedHashMap
.
✐ Examples
1 Create an empty LinkedHashMap without specifying key-value types
In this example,
- We create an empty LinkedHashMap by calling
Map()
without specifying key-value types. - The resulting
emptyMap
variable is empty, as it has no key-value pairs. - We print the
emptyMap
to standard output.
Dart Program
void main() {
var emptyMap = Map();
print('Empty map: $emptyMap');
}
Output
Empty map: {}
2 Create an empty LinkedHashMap with integer keys and string values
In this example,
- We create an empty LinkedHashMap with key type
int
and value typeString
by callingMap
.() - The resulting
emptyMap
variable is empty, as it has no key-value pairs. - We print the
emptyMap
to standard output.
Dart Program
void main() {
var emptyMap = Map<int, String>();
print('Empty map: $emptyMap');
}
Output
Empty map: {}
3 Create an empty LinkedHashMap with string keys and dynamic values
In this example,
- We create an empty LinkedHashMap with key type
String
and value typedynamic
by callingMap
.() - The resulting
emptyMap
variable is empty, as it has no key-value pairs. - We print the
emptyMap
to standard output.
Dart Program
void main() {
var emptyMap = Map<String, dynamic>();
print('Empty map: $emptyMap');
}
Output
Empty map: {}
Summary
In this Dart tutorial, we learned about Map constructor of Map: the syntax and few working examples with output and detailed explanation for each example.