← All languages
Dart function of the day
Random

join

Concatenate elements of an iterable into a single string.

Description

The join method converts each element of the iterable to a String using toString() and concatenates them with the specified separator between each pair of adjacent elements. If no separator is provided, the elements are concatenated directly with no delimiter.

This method eagerly evaluates the entire iterable to build the resulting string. It is the Dart equivalent of array join methods found in many other languages.

The join method is especially handy for building comma-separated values, path components, or any formatted string output from a collection of items.

Arguments

NameDescriptionOptional
separator The string to place between each element. Defaults to an empty string. Yes

Example

var words = ['Hello', 'Dart', 'World'];
print(words.join(' ')); // 'Hello Dart World'
print(words.join(', ')); // 'Hello, Dart, World'
print([1, 2, 3].join('-')); // '1-2-3'

Reference