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,
- We declare an integer variable named
numberwith the value123. - We then call the
toString()method onnumberto convert it to a string. - The resulting string
strcontains the string representation of the number. - 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,
- We declare a string variable named
textwith the value'Hello, world!'. - We then call the
toString()method ontextto get its string representation. - The resulting string
stris the same as the original string. - 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.