join method

String join (
  1. [String separator = ""]
)
inherited

Converts each element to a String and concatenates the strings.

Iterates through elements of this iterable, converts each one to a String by calling Object.toString, and then concatenates the strings, with the separator string interleaved between the elements.

Implementation

String join([String separator = ""]) {
  int length = this.length;
  if (!separator.isEmpty) {
    if (length == 0) return "";
    String first = "${elementAt(0)}";
    if (length != this.length) {
      throw new ConcurrentModificationError(this);
    }
    StringBuffer buffer = new StringBuffer(first);
    for (int i = 1; i < length; i++) {
      buffer.write(separator);
      buffer.write(elementAt(i));
      if (length != this.length) {
        throw new ConcurrentModificationError(this);
      }
    }
    return buffer.toString();
  } else {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < length; i++) {
      buffer.write(elementAt(i));
      if (length != this.length) {
        throw new ConcurrentModificationError(this);
      }
    }
    return buffer.toString();
  }
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-collection/ListQueue/join.html