Dart List toString()
Syntax & Examples


Syntax of List.toString()

The syntax of List.toString() method is:

 String toString() 

This toString() method of List a string representation of this object.

Return Type

List.toString() returns value of type String.



✐ Examples

1 Convert number to string

In this example,

  1. We declare an integer variable named number with the value 123.
  2. We then call the toString() method on number to convert it to a string.
  3. The resulting string str contains the string representation of the number.
  4. We print the string to standard output.

Dart Program

void main() {
  int number = 123;
  var str = number.toString();
  print(str); // Output: 123
}

Output

123

2 Convert string to string

In this example,

  1. We declare a string variable named text with the value 'Hello, world!'.
  2. We then call the toString() method on text to get its string representation.
  3. The resulting string str is the same as the original string.
  4. We print the string to standard output.

Dart Program

void main() {
  String text = 'Hello, world!';
  var str = text.toString();
  print(str); // Output: Hello, world!
}

Output

Hello, world!

Summary

In this Dart tutorial, we learned about toString() method of List: the syntax and few working examples with output and detailed explanation for each example.