The syntax of List.toString() method is:
String toString()
This toString() method of List a string representation of this object.
List.toString() returns value of type String
.
In this example,
number
with the value 123
.toString()
method on number
to convert it to a string.str
contains the string representation of the number.void main() {
int number = 123;
var str = number.toString();
print(str); // Output: 123
}
123
In this example,
text
with the value 'Hello, world!'
.toString()
method on text
to get its string representation.str
is the same as the original string.void main() {
String text = 'Hello, world!';
var str = text.toString();
print(str); // Output: Hello, world!
}
Hello, world!
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.