Reputation: 56
I have problem and dont know to solve.
List<int> list= [1, 2, 3];
How to convert list above into this:
String data= '[1, 2, 3]';
Upvotes: 0
Views: 1365
Reputation: 11210
Another way. Independent of the built-in 'toString()'.
void main() {
final list = [1, 2, 3];
final data = '[${list.join(', ')}]';
print(data);
}
Upvotes: 0
Reputation: 101
please try this code
List<int> list= [1, 2, 3];String data = list.toString().replaceAll('[', "'[").replaceAll(']',"]'");print(data);
you can try it on the dart pad to know the solution
Upvotes: 1
Reputation: 27137
You can use toString() metohd.
String data = list.toString();
Upvotes: 4