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
number
with the value123
. - We then call the
toString()
method onnumber
to convert it to a string. - The resulting string
str
contains 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
text
with the value'Hello, world!'
. - We then call the
toString()
method ontext
to get its string representation. - The resulting string
str
is 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.