Lets say we have a list of integers:
List<int> integers=[4, 5];
I want to convert this List to string value like this:
String val="4,5"
How can I manage to do this in dart?
You can use join method to do so.
print(integers.join(","));
The shortest answer is
integers.join(',');
If you want more control over the operation where let's say you want to do additional computation at each iteration you can use this:
List<int> integers=[4, 5];
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < integers.length; i++) {
buffer.write(integers[i].toString() + ',');
}
//REMOVE LAST COMMA
String values = '';
if (integers.length > 0)
values = buffer.toString().substring(0, buffer.length -1);
print(values);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.