tovid
tovid

Reputation: 56

How to convert List<int> to String in Dart

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

Answers (3)

mezoni
mezoni

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

Sneha G Sneha
Sneha G Sneha

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

Viren V Varasadiya
Viren V Varasadiya

Reputation: 27137

You can use toString() metohd.

 String data =  list.toString();

Upvotes: 4

Related Questions