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
numberwith the value 42. - We call the
toString()method onnumberto 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
characterwith the value 'A'. - We call the
toString()method oncharacterto 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
messagewith the value 'Hello, world!'. - We call the
toString()method onmessageto 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.