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,

  1. We create a variable number with the value 42.
  2. We call the toString() method on number to convert it to a string.
  3. 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,

  1. We create a variable character with the value 'A'.
  2. We call the toString() method on character to convert it to a string.
  3. 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,

  1. We create a variable message with the value 'Hello, world!'.
  2. We call the toString() method on message to convert it to a string.
  3. 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.