Convert String into List of Characters
To convert given string into a list of characters in Dart, call split() method on the string and pass empty string as argument to the method. The method returns a list with the characters of the string as elements.
The syntax of expression to get the list of characters from the string myString
is
</>
Copy
myString.split('')
Dart Program
In the following program, we take a string 'apple'
in variable myString
, and convert the string into a list of characters.
main.dart
</>
Copy
void main() {
var myString = 'apple';
var output = myString.split('');
print(output);
}
Output
[a, p, p, l, e]
Conclusion
In this Dart Tutorial, we learned how to split the given string into a list of characters in Dart.