Dart .toString()

blog1357267845's avatar
Published May 10, 2024
Contribute to Docs

In Dart, the .toString() method converts the object into a string representation.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

Syntax

typeObject.toString()

Above, typeObject.toString() calls the toString() method on the object typeObject.

Example

The following example demonstrates how the .toString() method is used to convert numbers to a string:

void main() {
int numbers = 123;
var result = numbers.toString();
print(result);
}

The code shown above will generate the following output:

123

Note: The output 123 is a string. This can be confirmed by checking result is String and result.runtimeType.

All contributors

Contribute to Docs

Learn Dart on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours