toArray method Null safety

List<String>? toArray()

Returns a list of the string's characters.

O(n)

Example

String foo = 'abracadabra';
List<String> fooArray = foo.toStringArray(); // returns '[a,b,r,a,c,a,d,a,b,r,a]'

Implementation

List<String>? toArray() {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return [];
  }
  return this!.split('');
}