Dart .toString()
Published May 10, 2024
Contribute to Docs
In Dart, the .toString() method converts the object into a string representation.
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
123is a string. This can be confirmed by checkingresult is Stringandresult.runtimeType.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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