Spec-Zone.ru › Dart 2

dart:collection

Метод join

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

Преобразует каждый элемент в строку и конкатенирует строки.

Проходит по элементам этого итерируемого объекта, преобразует каждый в строку, вызывая Object.toString, а затем конкатенирует строки, вставляя между элементами строку separator.

Пример:

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

Реализация

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

© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.18.5/dart-collection/ListQueue/join.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API