join method

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

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.

Example:

final planetsByMass = <double, String>{0.06: 'Mercury', 0.81: 'Venus',
  0.11: 'Mars'};
final joinedNames = planetsByMass.values.join('-'); // Mercury-Venus-Mars

Implementation

String join([String separator = ""]) {
  Iterator<E> iterator = this.iterator;
  if (!iterator.moveNext()) return "";
  var first = iterator.current.toString();
  if (!iterator.moveNext()) return first;
  var buffer = StringBuffer(first);
  // TODO(51681): Drop null check when de-supporting pre-2.12 code.
  if (separator == null || separator.isEmpty) {
    do {
      buffer.write(iterator.current.toString());
    } while (iterator.moveNext());
  } else {
    do {
      buffer
        ..write(separator)
        ..write(iterator.current.toString());
    } while (iterator.moveNext());
  }
  return buffer.toString();
}