What is the Strings.join() method in Dart?

The Strings.join() method is used to concatenate strings in Dart programming. In Dart, we can easily combine a list’s elements into a single string with the Strings.join() method.

Syntax:
list_name.join('input_string(s)');

The input string(s) are added between each element of the list in the output string.

Example

The code below concatenates elements in the list.

// Main function
void main() {
// Creating List of strings
List<String> myList = ["Educative", "shot"];
List<String> myList2 = ["Orange", "banana", "mango", "apple"];
// Using String.join() to convert elements of the list
// into a String
String edu1 = myList.join();
// display the concatenated string
print(edu1);
// adding space between the items
String edu2 = myList.join(" ");
print(edu2);
// adding comma ',' between the items in the list
String fruits = myList2.join(', ');
print(fruits);
}

Free Resources