метод join
- [String separator = ""]
унаследовано
Преобразует каждый элемент в String и объединяет строки.
Перебирает элементы этой итерируемой коллекции, преобразует каждый из них в String, вызывая 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.19.6/dart-collection/ListQueue/join.html