Dart Map toString()
Syntax & Examples
Syntax of Map.toString()
The syntax of Map.toString() method is:
String toString()
This toString() method of Map a string representation of this object.
Return Type
Map.toString() returns value of type String
.
✐ Examples
1 Convert number to string
In this example,
- We create a variable
number
with the value 42. - We call the
toString()
method onnumber
to convert it to a string. - The resulting string is printed to standard output.
Dart Program
void main() {
var number = 42;
print(number.toString());
}
Output
42
2 Convert character to string
In this example,
- We create a variable
character
with the value 'A'. - We call the
toString()
method oncharacter
to convert it to a string. - The resulting string is printed to standard output.
Dart Program
void main() {
var character = 'A';
print(character.toString());
}
Output
A
3 Convert message to string
In this example,
- We create a variable
message
with the value 'Hello, world!'. - We call the
toString()
method onmessage
to convert it to a string. - The resulting string is printed to standard output.
Dart Program
void main() {
var message = 'Hello, world!';
print(message.toString());
}
Output
Hello, world!
Summary
In this Dart tutorial, we learned about toString() method of Map: the syntax and few working examples with output and detailed explanation for each example.